Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 363563

Summary: Run As Java Application hangs when executing Runtime.exec("java ...")
Product: [Eclipse Project] JDT Reporter: Robert.Welters
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard: stalebug
Attachments:
Description Flags
Eclipse Java Project containing the test class.
none
Screen shot of the remote debugging stack trace none

Description Robert.Welters CLA 2011-11-11 05:13:54 EST
Build Identifier: 20110301-1815

The only class in my Java Project is:

public class RuntimeExcecutor {
   public static void main(String[] args) throws Exception {
      Process process = Runtime.getRuntime().exec("java one/two/three/DoesNotExist.class");
      process.waitFor();
   }
}

When I run this class via a run configuration or directly via "Run As" -> "Java Application" then the execution hangs. Of course, the execution of the java command inside of Runtime.exec() is not expected to be successful, as the called class does not exist. However, the run configuration should not hang.

When I add debugging options to the java command inside of the Runtime.exec() and use remote debugging then I can see that the execution hangs with the following stack trace:
RuntimeExcecutor_Debugger [Remote Java Application]   
   Java HotSpot(TM) Client VM[localhost:8000]   
      Thread [main] (Suspended)   
         FileOutputStream.writeBytes(byte[], int, int) line: not available [native method]   
         FileOutputStream.write(byte[], int, int) line: 260   
         BufferedOutputStream.flushBuffer() line: 65   
         BufferedOutputStream.flush() line: 123   
         PrintStream.write(byte[], int, int) line: 432   
         StreamEncoder.writeBytes() line: 202   
         StreamEncoder.implFlushBuffer() line: 272   
         StreamEncoder.flushBuffer() line: 85   
         OutputStreamWriter.flushBuffer() line: 168   
         PrintStream.write(String) line: 477   
         PrintStream.print(String) line: 619   
         PrintStream.println(String) line: 756   
         ClassNotFoundException(Throwable).printStackTraceAsCause(PrintStream, StackTraceElement[]) line: 490   
         NoClassDefFoundError(Throwable).printStackTrace(PrintStream) line: 468   
         NoClassDefFoundError(Throwable).printStackTrace() line: 451   

The problem seems that writing to the console is inhibited.
The above class is made minimal just for demonstration purposes. In my actual program I use Runtime.exec() to call a java program that prints to System.out and/or logs to the console and hangs there.

Reproducible: Always

Steps to Reproduce:
1. Create a Java Project with just one class as shown above (can be in the default package).
2. In the .java file of the class click the right mouse button and select "Run As" -> "Java Application".
3. The started run configuration hangs and never finishes, i.e. the red square button "Stop" remains enabled. In the debug perspective one can see the running program.
4. In order to find the line where it hangs add debug options:
Process process = Runtime.getRuntime().exec("java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -DebugPort=8000 one/two/three/DoesNotExist.class");
5. After the program hangs, start a Remote Java Application Debug Configuration.
6. In the debug perspective suspend the remote debugging thread to see the stack trace as shown above.
7. By the way, the remote debugger does not connect, if I have less than three package levels specified for my not existing class, but the actual application still hangs.
Comment 1 Robert.Welters CLA 2011-11-11 05:19:59 EST
Created attachment 206833 [details]
Eclipse Java Project containing the test class.
Comment 2 Robert.Welters CLA 2011-11-11 05:20:59 EST
Created attachment 206834 [details]
Screen shot of the remote debugging stack trace
Comment 3 Eclipse Genie CLA 2019-10-03 04:28:08 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.