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.

Bug 194151

Summary: <java inputstring="..."> when run inside IDE causes java output not to be displayed
Product: projects Reporter: rongoldman <rongoldman>
Component: AntAssignee: Jesse Glick <jglick>
Status: VERIFIED FIXED    
Severity: normal Keywords: REGRESSION
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Bug Depends on: 68770, 168153    
Bug Blocks: 121512, 167279    
Attachments: Suggested patch

Description rongoldman 2011-01-09 10:37:00 UTC
This looks related to bug 121512. If I run the test case given in Comment #1 in a shell outside the IDE I get:

    [javac] Compiling 1 source file to /var/folders/Xa/Xa8rahWIk+++TM/-Tmp- 
     [java] got: some text 
 
    BUILD SUCCESSFUL 
    Total time: 1 second 

Running the same target in the IDE displays in the IDE Output Window:

    Compiling 1 source file to /var/folders/Xa/Xa8rahWIk+++TM/-Tmp-
    BUILD SUCCESSFUL (total time: 0 seconds)

Note that there is no output displayed from the java task. If I specify an "outputproperty" to the java task then I can get the output, but that won't work for my application since sometimes the task will run for a very long time & I want to display the output as it is written.

Is it the case that NetBeans replaces the standard ant java task with a special NetBeans version? Is there some way in my build.xml file to disable that & just use the standard ant java task? Or can the NetBeans version be made smarter so that if neither "output" or "outputproperty" is specified in the java task, then java output will be displayed in the IDE Output Window?

I need a workaround that can be done solely in the ant target as the target is part of a library that other users include in their NetBeans projects (i.e. I don't control the nbproject/project.xml file).

fyi: I just downloaded the 7.0 Beta and it behaves the same as 6.9.1

-- Ron --

p.s. from the About NetBeans info:

Product Version: NetBeans IDE 6.9.1 (Build 201007282301)
Java: 1.6.0_22; Java HotSpot(TM) 64-Bit Server VM 17.1-b03-307
System: Mac OS X version 10.6.6 running on x86_64; MacRoman; en_US (nb)
Comment 1 rongoldman 2011-01-12 02:12:32 UTC
Looking at the definition of the ForkedJavaOverride class (in package org.apache.tools.ant.module.bridge.impl) I think the problem is caused because both setInput() & setInputString() call useStandardRedirector():

     public @Override void setInput(File input) {
         useStandardRedirector();
         super.setInput(input);
     }
     public @Override void setInputString(String inputString) {
         useStandardRedirector();
         super.setInputString(inputString);
     }

I think that useStandardRedirector() should only be called when the output is being redirected via setOutput(), setOutputProperty(), setError() or setErrorProperty(). If the java target is only redirecting the input, then the output should go to the normal place, the Output Window.

A simple fix might be to change setInput(), setInputString() & useStandardRedirector() to something like:

     private File useInput = null;
     private String useInputString = null;
     public @Override void setInput(File input) {
         useInput = input;
         super.setInput(input);
     }
     public @Override void setInputString(String inputString) {
         useInputString = inputString;
         super.setInputString(inputString);
     }
     private void useStandardRedirector() { // #121512, #168153
         if (redirector instanceof NbRedirector) {
             redirector = new Redirector(this);
             if (useInput != null) super.setInput(useInput);
             if (useInputString != null) super.setInputString(useInputString);
         }
     }
Comment 2 Jesse Glick 2011-01-12 16:58:39 UTC
I'll see if I can reproduce and if a fix like you suggest works and causes no apparent regressions elsewhere. (Dealing with Ant's I/O system is rather tricky.)
Comment 3 Jesse Glick 2011-02-10 23:12:30 UTC
Created attachment 105845 [details]
Suggested patch

Does not work; when test case from bug #121512 comment #1 is run, process just hangs waiting for input.
Comment 4 Jesse Glick 2011-02-10 23:34:09 UTC
Seems to have regressed in 6.8. Perhaps the fix of bug #168153 was responsible, but I cannot get it to work in 7.0 even using the class as it existed in 6.7. Nor does using an older version of Ant help (both 6.7 and 6.8 use 1.7.1 so that's not surprising). Even disabling ForkedJavaOverride completely does not help.
Comment 5 Jesse Glick 2011-02-11 01:29:53 UTC
hg bisect says:

The first bad revision is:
changeset:   135936:8147e07a4e5d
parent:      135879:96071a38dc62
user:        Tomas Holy <t_h@netbeans.org>
date:        Tue Jun 23 12:28:24 2009 +0200
summary:     #167279: Double echo on output in Output window
Comment 6 Jesse Glick 2011-02-11 02:57:05 UTC
I think I have a fix. Try: core-main #8f9fd1b9dfaf

Failing that, the simplest workaround seems to be:

 <taskdef name="_java" classname="org.apache.tools.ant.taskdefs.Java"/>
 <_java ... inputstring="some text"/>

If bug #68770 is implemented this and related issues would be obsolete.
Comment 7 rongoldman 2011-02-11 03:33:23 UTC
Both the fix & the workaround solve the problem! 

Many thanks.
Comment 8 Jesse Glick 2011-02-11 14:48:22 UTC
Good. By the way, the fix is clumsy in that it sets a flag which will be present for the rest of the project's execution, possibly causing bug #167279 to regress for _subsequent_ <java> invocations. I hope this is rare; if not, it should be possible to somehow unset the flag when the task is done. I initially tried calling setTaskName("origjava") but this had no apparent effect on Event.getTaskName(); that would be a cleaner fix if it can be made to work.
Comment 9 Quality Engineering 2011-02-16 11:39:33 UTC
Integrated into 'main-golden', will be available in build *201102160501* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/8f9fd1b9dfaf
User: Jesse Glick <jglick@netbeans.org>
Log: #194151: <java inputstring="..."/> fails to print any output.