Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8154036

Java.exe corrupts command line arguments

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)


      FULL OS VERSION :
      Windows 7 Professional, 64 bit, Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      According to the documentation of the JAVA tool, the command line arguments following the class name are supposed to be mapped to the "args" parameter of the MAIN method. However if the characters "\*\" (backslash, asterisk, backslash) occur in an argument, then the argument is modified in a very strange way:

      It appears that in the character sequence
            '\' '*' { '\' '*' }
      , the nth backslash is replaced with n backslashes.

      This behavior causes subtle problems e.g. if you write a GREP utility in Java and use it to find DOC comments in a java source file, like this:

      $ java com.acme.Grep '/\*\*' *.java
      $

      Even though "/\*\*" is the correct regular expression to match "/**" (the beginning of a DOC comment), no matches will be found because due to the described bug the command line argument "/\*\*" is silently changed to "/\*\\*", which no longer matches "/**".

      The bug is reproducible with the following WINDOWS JREs:
         jre1.7.0_80
         jre1.7.0_80 (32 bit)
         jre1.8.0_45
         jre1.8.0_45 (32 bit)

      The bug does NOT occur with the following WINDOWS JREs:
         jre1.5.0_17 (32 bit)
         jre1.6.0_42


      THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes

      THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

      REGRESSION. Last worked in version 6u45

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the "source code for an executable test case", below.

      Run it as follows:

      --------------------
      $ java.exe foo.Echo 'aaa\*\*\*\*\*\a\*\*\*bbb'
      aaa\*\\*\\\*\\\\*\\\\\*\\\\\\a\*\\*\\\*bbb
      $
      --------------------

      The purpose of the single quotes is to prevent the command shell (BASH in this case) to process the backslashes before running java.exe.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected program output:
      aaa\*\*\*\*\*\a\*\*\*bbb

      Actual program output:
      aaa\*\\*\\\*\\\\*\\\\\*\\\\\\a\*\\*\\\*bbb
      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package foo;

      public class Echo {

          public static void main(String[] args) {
              for (String arg : args) {
                  System.out.println(arg);
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None known.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              aroy Abhijit Roy (Inactive)
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: