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 270831 - Project Properties Setting "Enable JShell access" doesn't work
Summary: Project Properties Setting "Enable JShell access" doesn't work
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Project (show other bugs)
Version: Dev
Hardware: PC Mac OS X
: P1 normal (vote)
Assignee: Tomas Zezula
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-08 06:52 UTC by maxnitribitt
Modified: 2017-07-28 14:32 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
error message (808 bytes, text/rtf)
2017-06-30 07:31 UTC, maxnitribitt
Details
messages.log (68.81 KB, application/octet-stream)
2017-07-02 13:34 UTC, maxnitribitt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description maxnitribitt 2017-06-08 06:52:05 UTC
I'm trying to run the Anagram game with JShell integration. To do that I go to Project Properties, open "run" category and enable the CheckBox "Enable JShell access". When I close the Properties and open it again, the setting is gone.

I made a little screencast:
https://www.youtube.com/watch?v=F7Qw8agFdIY&feature=youtu.be
Comment 1 maxnitribitt 2017-06-08 07:37:07 UTC
Product Version: NetBeans IDE Dev (Build 201706010001)
Updates: Updates available
Java: 9-ea; Java HotSpot(TM) 64-Bit Server VM 9-ea+171
Runtime: Java(TM) SE Runtime Environment 9-ea+171
System: Mac OS X version 10.12.5 running on x86_64; UTF-8; de_DE (nb)
User directory: /Users/antonepple/Library/Application Support/NetBeans/dev
Cache directory: /Users/antonepple/Library/Caches/NetBeans/dev
Comment 2 maxnitribitt 2017-06-08 16:00:28 UTC
Same behaviour on Windows 10
Comment 3 Svata Dedic 2017-06-13 11:06:48 UTC
Please try to create a separate run configuration for your project and enable JShell in the non-default configuration. 
There was a bug regarding saving some of the default config properties you may be hitting in this case.
Comment 4 maxnitribitt 2017-06-30 07:27:22 UTC
Creating a separate run configuration helps. I can confirm that after that, the setting is persisted. But the application still doesn't run. It runs fine without jshell enabled.
Comment 5 maxnitribitt 2017-06-30 07:31:58 UTC
Created attachment 164662 [details]
error message

Here's the error message. I can't copy and paste it, as it will be classified as SPAM.
Comment 6 maxnitribitt 2017-06-30 07:33:02 UTC
And these are my current versions and settings
Product Version: NetBeans IDE Dev (Build 201706290001)
Java: 9; Java HotSpot(TM) 64-Bit Server VM 9+175
Runtime: Java(TM) SE Runtime Environment 9+175
System: Mac OS X version 10.12.5 running on x86_64; UTF-8; de_DE (nb)
User directory: /Users/antonepple/Library/Application Support/NetBeans/dev
Cache directory: /Users/antonepple/Library/Caches/NetBeans/dev
Comment 7 Svata Dedic 2017-06-30 10:22:48 UTC
Could you please attach your message.log file ?
Comment 8 Svata Dedic 2017-06-30 12:37:19 UTC
Just a speculation based on the provided error message. Spaces were not properly quoted, I've fixed quoting with jet-main#9b983c9a79fd; please check with a newer dev build.
Comment 9 Quality Engineering 2017-07-02 01:49:36 UTC
Integrated into 'main-silver', will be available in build *201707020001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/9b983c9a79fd
User: Svata Dedic <sdedic@netbeans.org>
Log: #270831: quoted possible spaces in agent specification / other arguments generated by JShell
Comment 10 maxnitribitt 2017-07-02 13:30:55 UTC
You were correct. The project launches now with the agent. This is the output:

Juli 02, 2017 3:23:06 NACHM. org.netbeans.lib.jshell.agent.NbJShellAgent premain
INFORMATION: Starting JShell agent loop

Still, I cannot start the JShell to attach to the running process. 
Here's what I did:

1. Install NB daily build from 20170702
2. Delete "dev" dir in ApplicationSupport/NetBeans to start with fresh userdir
3. Create Anagram Game from Samples
4. Make a new run config with JSHell enabled
5. Run the application (seems to work including agent, output see above) 
6. Go to "Run" Menu. "Open Java Shell for Project (AnagramGame5)" is disabled.

Strangely it was enabled when I first tried, but it showed some error messages about state and asked me to "/reload -restore" which I did, but the same error occurred. But now I cannot reproduce that. The action is never enabled. 

Should I open a new bug for that, or am I doing sthg wrong?
Comment 11 maxnitribitt 2017-07-02 13:34:41 UTC
Created attachment 164676 [details]
messages.log
Comment 12 maxnitribitt 2017-07-02 13:41:06 UTC
I can now reproduce the problem mentioned before:
If I right-click the project and open the JSHell using "Execute Java Shell", the JSHell opens and after that, the entry in "Run" Menu is enabled.

So steps to reproduce are:

1. Install NB daily build from 20170702
2. Delete "dev" dir in ApplicationSupport/NetBeans to start with fresh userdir
3. Create Anagram Game from Samples
4. Make a new run config with JSHell enabled
5. Run the application (seems to work including agent, output see above) 
6. Go to "Run" Menu. "Open Java Shell for Project (AnagramGame5)" is disabled.
7. right-click the project and open the JSHell using "Execute Java Shell"
8. Go to "Run" Menu. "Open Java Shell for Project (AnagramGame5)" is enabled. Click it.

Result: The JSHell is opened, but doesn't seem to work, error is:

|  State engine terminated.
|  Restore definitions with: /reload -restore
|  State engine terminated.
|  Restore definitions with: /reload -restore
[1]-> /reload -restore

|  State engine terminated.
|  Restore definitions with: /reload -restore
|  Java Shell cannot execute commands. Restart Java Shell or its host process.

[1]->
Comment 13 maxnitribitt 2017-07-02 14:10:27 UTC
Update: it works sometimes. 

But there's a new problem. I start NetBeans and try to execute JSHell from context menu to enable the Action in "Run". An Exception occurs and JSHell doesn'T start. Subsequent tries to execute JShell will open the TopComponent, but it's empty.(reported as #854893). This seems to be the cause:
SEVERE [org.openide.util.RequestProcessor]: Error in RequestProcessor org.apache.tools.ant.module.run.TargetExecutor$WrapperExecutorTask
java.lang.NullPointerException
	at org.netbeans.modules.jshell.support.ShellSession.initClasspath(ShellSession.java:1156)
	at org.netbeans.modules.jshell.support.ShellSession.init(ShellSession.java:1090)
	at org.netbeans.modules.jshell.support.ShellSession.start(ShellSession.java:521)
	at org.netbeans.modules.jshell.env.JShellEnvironment.doStartAndFire(JShellEnvironment.java:482)
	at org.netbeans.modules.jshell.env.JShellEnvironment.start(JShellEnvironment.java:423)
	at org.netbeans.modules.jshell.env.ShellRegistry.openProjectSession(ShellRegistry.java:241)
	at org.netbeans.modules.jshell.project.REPLAction2.doRunShell(REPLAction2.java:128)
	at org.netbeans.modules.jshell.project.REPLAction2.access$000(REPLAction2.java:65)
	at org.netbeans.modules.jshell.project.REPLAction2$1.finished(REPLAction2.java:117)
	at org.netbeans.modules.java.api.common.project.ActionProviderSupport$JavaModelWork.lambda$run$185(ActionProviderSupport.java:1310)
	at org.openide.util.Task.notifyFinished(Task.java:240)
	at org.openide.util.Task.run(Task.java:260)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1443)
	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:68)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:303)
	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2058)
Caused: org.openide.util.RequestProcessor$SlowItem: task failed due to
	at org.openide.util.RequestProcessor.post(RequestProcessor.java:420)
	at org.apache.tools.ant.module.run.TargetExecutor.execute(TargetExecutor.java:433)
	at org.apache.tools.ant.module.api.AntTargetExecutor.execute(AntTargetExecutor.java:123)
	at org.apache.tools.ant.module.api.support.ActionUtils.runTarget(ActionUtils.java:125)
	at org.netbeans.modules.java.api.common.project.ActionProviderSupport$JavaModelWork.execute(ActionProviderSupport.java:1365)
	at org.netbeans.modules.java.api.common.project.ActionProviderSupport$JavaModelWork.run(ActionProviderSupport.java:1306)
	at org.netbeans.modules.java.api.common.project.ActionProviderSupport.invokeTarget(ActionProviderSupport.java:238)
	at org.netbeans.modules.java.api.common.project.JavaActionProvider$ScriptAction.invoke(JavaActionProvider.java:486)
	at org.netbeans.modules.java.api.common.project.JavaActionProvider.lambda$invokeAction$171(JavaActionProvider.java:916)
	at java.base/java.util.Optional.ifPresent(Optional.java:175)
	at org.netbeans.modules.java.api.common.project.JavaActionProvider.invokeAction(JavaActionProvider.java:909)
	at org.netbeans.modules.java.api.common.project.BaseActionProvider.invokeAction(BaseActionProvider.java:249)
	at org.netbeans.modules.java.j2seproject.J2SEActionProvider.lambda$invokeAction$0(J2SEActionProvider.java:315)
	at org.netbeans.modules.java.j2seproject.J2SEActionProvider.invokeAction(J2SEActionProvider.java:360)
	at org.netbeans.spi.project.support.LookupProviderSupport$MergedActionProvider.invokeAction(LookupProviderSupport.java:287)
	at org.netbeans.modules.jshell.project.REPLAction2.perform(REPLAction2.java:108)
	at org.netbeans.modules.project.ui.actions.ProjectAction$1$1.run(ProjectAction.java:142)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764)
	at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
	at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
	at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:199)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
[catch] at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Comment 14 Svata Dedic 2017-07-21 08:07:55 UTC
Re. enabling the action, comment #$10. Please note that "Execute Java Shell" in the project menu is a different action: starts a new VM configured to load classes from the project (and its dependents).

Run | Open Java Shell for X action opens a shell for an already running project. As all actions in the Run menu, it works on the "current" project, or the main one, if main project is set up. The "current" project tracks the editor/top component, so to have the menu item enabled, you need either:
* select the project in Projects window
* give focus to an editor with file from the project
* set the project as the main one
In your case, "Execute Java Shell" from context menu (step 7) provided the project context, as the shell and its console window is bound to the project, and the console window (I assume) became the active one.

Re. exception: I am not 100% sure how that could happen since I cannot reproduce it, but there's a slight chance that the document got garbage collected during initialization. changeset jet-main#3edb913e766f should fix that.

Bureaucracy note: please file new issues for each discovered bug; this issue  initially talked about bug in project profiles support :)
Comment 15 Quality Engineering 2017-07-26 02:09:23 UTC
Integrated into 'main-silver', will be available in build *201707260001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/3edb913e766f
User: Svata Dedic <sdedic@netbeans.org>
Log: #270831: keep document open while the shell is being initialized
Comment 16 Svata Dedic 2017-07-28 14:32:31 UTC
The remaining issue is the project configuration persistence; the default config, does not save the JShell related properties.

Reassigning to the java projects to track the fix. If you encounter further JShell related bugs, please file a new issue. Thanks.