[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#296456: java wrapper script mishandles command line options with arguments



Package: gij-3.4
Version: 3.4.3-9
Tags: patch

The "java" wrapper script doesn't correctly handle command line options
with arguments (e.g. -classpath and -jar) so it doesn't handle cases
like this correctly:

java -classpath myjavaclasses -Djava.library.path=myjni Foo

Once it sees "myjavaclasses", the script switches to just copying
remaining arguments, so it the special handling for -Djava.library.path
doesn't kick in.

I've attached a patch to fix this.

Cheers,
    Olly
--- /usr/bin/java	2004-12-18 23:40:26.000000000 +0000
+++ java	2005-02-22 15:20:11.135688449 +0000
@@ -28,12 +28,20 @@
 
 # Build the command-line from the arguments given.
 my $parsingOptions = 1;
+
+# Flag used to copy argument to -classpath, -cp, -jar.
+my $copyNext = 0;
 foreach my $arg (@ARGV) {
   if (not $parsingOptions) {
     # We're done parsing options; just copy all remaining arguments directly.
     push @commandLine, $arg;
     next;
   }
+  if ($copyNext) {
+    push @commandLine, $arg;
+    $copyNext = 0;
+    next;
+  }
 
   # Try to interpret Sun-style options.
   if ($arg eq '-version') {
@@ -42,8 +50,10 @@
     push @commandLine, '--help';
   } elsif ($arg eq '-cp' or $arg eq '--cp') {
     push @commandLine, '-cp';
+    $copyNext = 1;
   } elsif ($arg eq '-classpath' or $arg eq '--classpath') {
     push @commandLine, '-classpath';
+    $copyNext = 1;
   } elsif ($arg =~ /^-Djava.library.path=(.+)$/) {
     # A component of the JNI search path has been given.
     if ($JNIPath) {
@@ -51,7 +61,11 @@
     } else {
       $JNIPath = $1;
     }
-  } elsif ($arg eq '-jar' or $arg =~ /^-D/) {
+  } elsif ($arg eq '-jar') {
+    # Copy the argument directly.
+    push @commandLine, $arg;
+    $copyNext = 1;
+  } elsif ($arg =~ /^-D/) {
     # Copy the argument directly.
     push @commandLine, $arg;
   } elsif ($arg =~ /^-/) {

Reply to: