This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
[ BUILD # : Dev 20050312 ] [ JDK VERSION : 1.5.0_01 ] Neither the final newline of text output using System.out.println(...), nor any text output using System.out.print(...) that does not end in a newline, is displayed in the output window, even if you call System.out.flush(). This is not readily seen if there is no console input or you do not sleep the main thread. It is a real problem for console input prompts, since they are never displayed until the next line that does end in a newline is displayed. Using this snippet, you can see this behavior. The output window displays "Console Test", but the cursor remains at the end of that line (not displaying the EOL) and does not display the prompt (not displaying text that does not end in an EOL). When you enter a line of text and hit return, the prompt is finally displayed, followed by the input line. ----- package com.TheSnakePitDev.Test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.System.out; public class Main { public static void main(String[] args) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); out.println("Console Test"); out.print("> "); out.flush(); String line; try { line = in.readLine(); if (line == null) line = "<Null>"; } catch (IOException e) { line = "<Exception>"; } out.println(line); } } -----
i've noticed lately that print() and write() methods are not properly implemented in output2, everything is line based. I'm trying to come up with a fix, not sure it makes it into 4.1 though. How does ant handle reading (or is it printing?) of lines? line by line, or by character?
Mostly line by line, I think. Note that running such a program inside Ant from the command shell doesn't really work either (using a trunk Ant with console input support, <java fork="true" .../>): $ /space/src/ant/dist/bin/ant -f /tmp/main.xml Buildfile: /tmp/main.xml x: [java] Console Test [[[I type here: 'foo']]] [java] > foo BUILD SUCCESSFUL Total time: 7 seconds I.e. it is probably ultimately an Ant bug that cannot be fixed in NetBeans, thus needs to be filed as such. More investigation likely required.
while it can be an ant bug, we're not innocent either. Some PrintWriter methods are ignored and some are converted to println() in the current implementation, which is wrong.
on branch ISSUE_56341 I've rewritten the storage, Lines model and Output writer to accept single charaters, incomplete lines etc. covered by tests.
Fixing the OW won't make any difference for Ant uses since Ant only sends complete lines. Just FYI.
the partial line fix code is actually in trunk, reassigning to ant. Jesse, feel free to close if you have a separate bug for the ant part of the process, I could not find it.
Cannot be fixed in NetBeans alone. Not for 5.0.
*** Issue 68617 has been marked as a duplicate of this issue. ***
*** Issue 71637 has been marked as a duplicate of this issue. ***
*** Issue 74019 has been marked as a duplicate of this issue. ***
*** Issue 74270 has been marked as a duplicate of this issue. ***
I have at least a partial solution to the problem that I applied to the Netbeans BlueJ edition. 1. I have a special ant task that extends the java task and reroutes it's output+input directly to the output window. 2. I have this task to map over the default java task. So when running within the IDE, my task gets called instead of the default java one. advantages: 1. separate tab for user program output 2. reading character by character results in partial lines being shown as well 3. no ant script tweaks, should run also with a custom ant on the command line (but in the wrong mode of line-by-line) drawbacks: 1. prints out a warning to the build output. 2. reading char-by-char is not optimized for high throughtput. 3. writing System.out.print("1"); System.out.print("2"); System.out.print("3"); System.out.print("GO"); will only print out 1 and then wait for the finish of the line. From a brief evaluation, it looks like a bug in output window implementation.
This sounds promising. Comments: Adv #1 is not specific to this implementation. Any AntLogger could choose to send output elsewhere if it wanted. Conversely, using a special task could send output to the build tab if desired (might require an API modification; TBD). Adv #2 is the key. Adv #3 is not a goal, it is a constraint. Dr #1 may be solvable using AntLogger. Dr #2 is probably solvable using local optimizations. Just read into a byte[] buffer and write as much as you can get at once. Dr #3 does sound like an OW bug. Another aspect of getting a direct handle on the j.l.Process that I have been thinking about is that it would make it more feasible to do things like initiate thread dumps in the target process (or more generally use the JDK 6 Attach API to do all sorts of nice things). You still need a mapping from Process instance to remote VM ID. On the Sun Unix JDK I know this is easy (using reflection); on other vendor/platform combos it is probably still feasible.
Dr.1: i'm not sure where the message is coming from. it appears in the output tab even before the buildStarted(AntEvent event) method is called in my antlogger.
Dr#3 is fixed in trunk.
*** Issue 64037 has been marked as a duplicate of this issue. ***
*** Issue 45294 has been marked as a duplicate of this issue. ***
*** Issue 18508 has been marked as a duplicate of this issue. ***
*** Issue 98940 has been marked as a duplicate of this issue. ***
*** Issue 108961 has been marked as a duplicate of this issue. ***
*** Issue 108570 has been marked as a duplicate of this issue. ***
To be evaluated for 6.0. Now, as the input is integral part of the output area, this one is still remaining to have the "input in output" experience complete.
No minor fix is possible; need to completely change how the IDE interacts with external processes spawned from Ant, by replacing the <java> task. Promising but too risky for 6.0.
*** Issue 102079 has been marked as a duplicate of this issue. ***
*** Issue 68770 has been marked as a duplicate of this issue. ***
Created attachment 46591 [details] Useful test class
Created attachment 46604 [details] More interesting test case
Also instructive to override -init-macrodef-java and modify <java>: output="/tmp/out" error="/tmp/err" input="/tmp/names" where ---%<--- /tmp/names Joe Bob ---%<---
I think I have it. A lot of subtleties here, may be regressions I don't know about yet. What I can confirm works: 1. System.out.print with no trailing newline gets printed, and you can use System.in after a prompt. 2. Works on Ubuntu and XP, including differing newline conventions. 3. Stack traces in process output still hyperlinked. 4. System.out and .err distinguished by color. 5. input="...", output="...", and error="..." on <java> work. 6. Entering and printing non-ASCII text (Czech) works on Ubuntu (UTF-8 system encoding). 7. Output missing a final newline at program end is still printed. 8. Performance of large output still seems reasonable. 9. Stopping a build in the middle of producing output succeeds and produces no visible exceptions or other errors (that I can find). What I know does not work: 1. java.io.Console. (See issue #68770.) 2. Lines of input get retroactively shifted down to a new line after pressing Enter. Probably core/output2 bug. 3. Perhaps same as #2: partial lines of text, while printed, are incorrectly followed by a newline in the display. Definitely a core/output2 bug. 4. Programs which send characters other than newline to output incrementally at intervals of less than 250 msec will not display that output until EOL or a longer pause. Might affect, for example, the line of dots printed by programs like jhat when starting up. 5. Conversely to #4, programs which send complete lines which is piped into NB extremely slowly (e.g. under heavy system load) might see portions sent as incomplete lines, which (besides the compound effect of problem #3) might result in missing stack trace hyperlinking. 6. Ant scripts which override <java> themselves (e.g. nbjdk.xml) might not see the benefit of this bug fix. Should not affect j2seproject, and probably irrelevant for NBM projects, but might affect freeform projects with custom JDKs configured which use stdio. Not yet tested. I think these issues are relatively minor compared to this bug and are thus not blockers. Checking in src/org/apache/tools/ant/module/bridge/AntBridge.java; /shared/data/ccvs/repository/ant/src/org/apache/tools/ant/module/bridge/AntBridge.java,v <-- AntBridge.java new revision: 1.37; previous revision: 1.36 done RCS file: /shared/data/ccvs/repository/ant/src-bridge/org/apache/tools/ant/module/bridge/impl/ForkedJavaOverride.java,v done Checking in src-bridge/org/apache/tools/ant/module/bridge/impl/ForkedJavaOverride.java; /shared/data/ccvs/repository/ant/src-bridge/org/apache/tools/ant/module/bridge/impl/ForkedJavaOverride.java,v <-- ForkedJavaOverride.java initial revision: 1.1 done Checking in src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java; /shared/data/ccvs/repository/ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java,v <-- BridgeImpl.java new revision: 1.44; previous revision: 1.43 done Checking in src/org/apache/tools/ant/module/run/StandardLogger.java; /shared/data/ccvs/repository/ant/src/org/apache/tools/ant/module/run/StandardLogger.java,v <-- StandardLogger.java new revision: 1.12; previous revision: 1.11 done
What also works: 10. Running same program twice in parallel so two windows are shown; input sent to the right instance. Some QE verification would be very much appreciated.
Reverting (I hope temporarily) due to issue #112839, under investigation.
Found & fixed a problem with stream closing when running other tasks after <java> (see issue #112839). Checking in ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java; /shared/data/ccvs/repository/ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java,v <-- BridgeImpl.java new revision: 1.46; previous revision: 1.45 done Checking in ant/src-bridge/org/apache/tools/ant/module/bridge/impl/ForkedJavaOverride.java; /shared/data/ccvs/repository/ant/src-bridge/org/apache/tools/ant/module/bridge/impl/ForkedJavaOverride.java,v <-- ForkedJavaOverride.java new revision: 1.2; previous revision: 1.1 done
*** Issue 113753 has been marked as a duplicate of this issue. ***
For the record, this impl has been obsoleted by t_h's changes in ForkedJavaOverride.