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 178764 - System.console() returns null
Summary: System.console() returns null
Status: RESOLVED DUPLICATE of bug 68770
Alias: None
Product: projects
Classification: Unclassified
Component: Ant (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P2 normal with 2 votes (vote)
Assignee: Jesse Glick
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-17 02:09 UTC by tkellerer
Modified: 2010-01-29 09:09 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tkellerer 2009-12-17 02:09:26 UTC
I cannot run Java applications that use System.console()

System.console() always returns null when run from within NetBeans. So there is no way to use this Java 6 feature with NetBeans

I'm pretty sure this was working in earlier releases (definitely in 6.5)
Comment 1 Stanislav Aubrecht 2010-01-18 06:02:03 UTC
reassigning - pls feel free to pick a different bugzilla component if this is not an output window problem, thanks
Comment 2 Antonin Nebuzelsky 2010-01-29 07:05:19 UTC
I figured out that System.console() returns null if the project is started via ant regardless of version (NB 6.0 which bundles Ant 1.7.0 fails too) and regardless of parameters passed to "java" ant task.

The only difference makes running in "java" ant task without forking ant's JVM (fork="false"). You can use this as a workaround - go to Files tab, expand build.xml in your project, open the target -init-macrodef-java and change the fork parameter of java task.

I found other ant users complaining that running java from ant has this problem.

Reassigning to projects/ant.
Comment 3 Jesse Glick 2010-01-29 09:09:05 UTC
(In reply to comment #2)
> The only difference makes running in "java" ant task without forking ant's JVM

Not sure what you mean by this but it is probably beside the point. While you might be able to make System.console() return non-null, it will still not be conected to the IDE's output window (at best to the IDE's startup shell, if there is one).

At least on Unix, the reason is that the user process is not run in its own pseudotty, which is impossible to do from pure Java. An app run without a pty, just using normal System.in/out/err (file descriptor 0/1/2) redirection, will return null from System.console() as the Javadoc states.

Sorry, but not possible to fix without a lot of work which is not currently planned. (*) If you need to test an app which uses console features, you must run the java launcher from a shell window.


(*) Specifically, I think it would require:

1. switching CoS-mode execution to use an alternate JavaRunnerImplementation based on extexecution

2. adding pty support to extexecution using some native wrapper executables or perhaps JNI calls (should be possible on Unix, but I have no idea about Windows)

3. integrating lib.terminalemulator with openide.io and using this in place of the standard output window when a project requests raw-mode I/O (otherwise e.g. Console.readPassword cannot work as intended)

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