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

Crash if classpath is read from @argument file and the main gets option argument

    Details

    • Subcomponent:
    • Resolved In Build:
      b23
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Microsoft Windows 10 Pro (10.0.17763 build 17763)
      java version "11.0.4" 2019-07-16 LTS
      Java(TM) SE Runtime Environment 18.9 (build 11.0.4+10-LTS)
      Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.4+10-LTS, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      When launching a Java app with -classpath argument read from a file without newline and
      the app has an argument starting with dash e.g. "-test", JVM crashes, for example here is WinDbg stack trace of one crash:

      (5c8c.6ed8): Unknown exception - code c0000374 (!!! second chance !!!)
      ntdll!RtlReportFatalFailure+0x9:
      00007ffe`a887b049 eb00 jmp ntdll!RtlReportFatalFailure+0xb (00007ffe`a887b04b)
      0:013> k
       # Child-SP RetAddr Call Site
      00 00000074`651fe760 00007ffe`a887b013 ntdll!RtlReportFatalFailure+0x9
      01 00000074`651fe7b0 00007ffe`a888389e ntdll!RtlReportCriticalFailure+0x97
      02 00000074`651fe8a0 00007ffe`a8883baa ntdll!RtlpHeapHandleError+0x12
      03 00000074`651fe8d0 00007ffe`a881ecb1 ntdll!RtlpHpHeapHandleError+0x7a
      04 00000074`651fe900 00007ffe`a882d0ca ntdll!RtlpLogHeapFailure+0x45
      05 00000074`651fe930 00007ffe`a496c7eb ntdll!RtlFreeHeap+0x9ac4a
      06 00000074`651fe9d0 00007ffe`0a2e384c ucrtbase!_free_base+0x1b
      07 00000074`651fea00 00007ffe`0a1cb545 jvm!c2v_reprofile+0x2b332c
      08 00000074`651fea60 00007ffe`09e0a7ff jvm!c2v_reprofile+0x19b025
      09 00000074`651feaa0 00007ffe`09e0a6a1 jvm!JVM_EnqueueOperation+0x12440f

      If the app argument does not have dash: e.g. "test", everything works ok.

      Here is an example of command line that causes the crash:
      "C:\Program Files\Java\jdk-11.0.4\bin\java.exe" -Dfile.encoding=UTF-8 "@classpath.txt" Test -test

      Excerpt from output before the crash when (with "set _JAVA_LAUNCHER_DEBUG=true"):
      Main class is 'Test'
      App's argc is 1
          argv[ 0] = '-test'
      6849 micro seconds to load main class
      ----_JAVA_LAUNCHER_DEBUG----
      AppArgIndex: -1 points to (null)
      Warning: app args count doesn't match, 7 1
      passing arguments as-is.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create file "classpath.txt" with following content:
      -classpath .;C:\Users\haapaan\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\27.1-jre\e47b59c893079b87743cdcfb6f17ca95c08c592c\guava-27.1-jre.jar

      No newline at the end.

      Compile the Test.java:
      javac @classpath.txt Test.java

      Run Test.class:
      "C:\Program Files\Java\jdk-11.0.4\bin\java.exe" -Dfile.encoding=UTF-8 "@classpath.txt" Test -test

      That crashes almost every time.

      If I have a more complex Spring Boot Application, it crashes every time:
      "C:\Program Files\Java\jdk-11.0.4\bin\java.exe" -Dfile.encoding=UTF-8 "@longclasspath.txt" fi.trimico.mbus.MBusBatchApplication -test

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Print "Hello world" to stdout and not crash.
      ACTUAL -
      Access violation and the JVM crashes.

      ---------- BEGIN SOURCE ----------
      import com.google.common.collect.Collections2;
      import java.util.Arrays;
          
      public class Test {
          public static void main(String args[]) {
      Collections2.permutations(java.util.Arrays.asList(1,2,3));
      System.out.println("Hello world");
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Pass classpath some other way, e.g. directly in command line:
      "C:\Program Files\Java\jdk-11.0.4\bin\java.exe" -Dfile.encoding=UTF-8 -classpath .;C:\Users\haapaan\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\27.1-jre\e47b59c893079b87743cdcfb6f17ca95c08c592c\guava-27.1-jre.jar Test -test

      FREQUENCY : often


        Attachments

        1. argument.txt
          0.1 kB
        2. guava-27.1-jre.jar
          2.62 MB
        3. Test.java
          0.3 kB

          Issue Links

            Activity

              People

              • Assignee:
                henryjen Henry Jen
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: