strange java 7 behavior on windows ( star arg "*")

daniel lutoff daniel.lutoff at oracle.com
Fri Apr 13 08:27:15 UTC 2012


Hi all,

I've notice a strange java 7 behavior on windows when a "*" is used as 
argument:

Here is the test case, just printed out the args (pretty simple as you 
can see):

    public class TestStar
    {
       public static void main(String args[])
       {
         for (String _arg : args)
         {
           System.out.print(_arg + " ");
         }
         System.out.println();
       }
    }

On Unix, running  ' java TestStar "*" ', both on jdk6 and jdk7 produce 
the expected output:

    $ echo $JAVA_HOME

    $ ./jdk1.6.0_26/bin/java -version
    java version "1.6.0_26"
    Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
    Java HotSpot(TM) Server VM (build 20.1-b02, mixed mode)
    $ ./jdk1.6.0_26/bin/java TestStar "*"
    *
    $ ./jdk1.7.0/bin/java -version
    java version "1.7.0"
    Java(TM) SE Runtime Environment (build 1.7.0-b147)
    Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode)
    $ ./jdk1.7.0/bin/java TestStar "*"
    *
    $

On windows with jkd6, I've got the expected output:

    $ echo %JAVA_HOME%
    %JAVA_HOME%

    $ c:\Program Files\Java\jdk1.6.0_29\bin\java.exe -version
    'c:\Program' is not recognized as an internal or external command,
    operable program or batch file.

    $ "c:\Program Files\Java\jdk1.6.0_29\bin\java.exe" -version
    java version "1.6.0_29"
    Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
    Java HotSpot(TM) Client VM (build 20.4-b02, mixed mode, sharing)

    $ "c:\Program Files\Java\jdk1.6.0_29\bin\java.exe" TestStar "*"
    *

    $


On windows with jkd7, the output **IS NOT** the expected one. It seems 
that the "*" is interpreted and list the directory

    $ "c:\Program Files\Java\jdk1.7.0_03\bin\java.exe" -version
    java version "1.7.0_03"
    Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
    Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)

    $ "c:\Program Files\Java\jdk1.7.0_03\bin\java.exe" TestStar "*"
    TestStar.class

    $ "c:\Program Files\Java\jdk1.7.0_03\bin\java.exe" TestStar "\*"
    \$Recycle.Bin \a.bat \autoexec.bat \bar.emf \config.sys \dell
    \Documents and Set
    tings \FWLog.txt \Genius \hiberfil.sys
    \HP_CLJ_CP4020_CP4520_32bit_PCL6_HPDIU \H
    PDIU.log \MSOCache \pagefile.sys \partage \PerfLogs \Program Files
    \ProgramData
    \Recovery \System Volume Information \Users \Windows \xampp


Any info about this strange behavior?
Is it a bug?
Is there a workaround?

Thanks
Daniel






More information about the core-libs-dev mailing list