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

Bug 334870

Summary: Creating new JFrame hangs after creating BufferedReader Thread that reads from console
Product: [Eclipse Project] JDT Reporter: Tristan de Inés <tristan_de_ines>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Tristan de Inés CLA 2011-01-20 05:48:39 EST
Build Identifier: M20100211-1343

I'm guessing this is an Eclipse problem (possibly related to the Eclipse console) because the following works fine when running it from the Windows command line:

After creating and starting a Thread that sets up a BufferedReader to read input from System.in, the main thread hangs when creating a new JFrame. Hitting "Enter" on System.in (in the Eclipse console) finally makes the main thread continue and display the JFrame. This does not make sense to me as the Thread reading from System.in and the main Thread creating the JFrame are entirely unrelated.

This problem occurs every time when starting the program from Eclipse in run-mode. Curiously, starting the program in Eclipse debug-mode, makes it function correctly and create the JFrame.

Btw. creating the JFrame in the EDT thread doesn't solve this problem. This is another reason why I assume it is related to the Eclipse console.

Please regard the code in "Steps to reproduce".

Reproducible: Always

Steps to Reproduce:
Put the following code in a main() method:

Thread t  = new Thread(new Runnable() {
			@Override
			public void run() {
				BufferedReader br = new BufferedReader(new InputStreamReader(
						System.in));
				String s = "";
				while (s != null && !s.equals("exit")) {
					try {
						s = br.readLine();
						if (s != null) {
							System.out.println(s);
						}
					} catch (Exception e) {
						System.err.println(e.getLocalizedMessage());
					}
				}
			}
		});
		t.start();

		System.out.println("before");
		JFrame frame = new JFrame();
		System.out.println("after");
		frame.setSize(new Dimension(300, 200));
		frame.setVisible(true);

The main thread hangs in JFrame() and "after" is never printed. If the "Enter" key is hit on System.in and the reader processes the input, the main Thread finally continues and the frame is displayed.
Comment 1 Dani Megert CLA 2011-01-20 07:50:56 EST

*** This bug has been marked as a duplicate of bug 123894 ***
Comment 2 Dani Megert CLA 2011-01-20 07:51:11 EST

*** This bug has been marked as a duplicate of bug 309523 ***