Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links in output window stacktraces do not work (when they point to JDK code) #4516

Closed
maffe opened this issue Aug 18, 2022 · 11 comments · Fixed by #5091
Closed

Links in output window stacktraces do not work (when they point to JDK code) #4516

maffe opened this issue Aug 18, 2022 · 11 comments · Fixed by #5091
Labels
Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:bug Bug report or fix Maven [ci] enable "build tools" tests
Milestone

Comments

@maffe
Copy link

maffe commented Aug 18, 2022

Apache NetBeans version

Apache NetBeans 14

What happened

The links in stacktraces to JDK code do not work with JDK 9+.

How to reproduce

Run any code causing an exception in JDK code in a Maven project, for example:

package com.acme.bugs.netbeans;

import java.io.FileNotFoundException;
import java.io.FileReader;

public class StacktraceLink {
    public static void main(final String[] args) throws FileNotFoundException {
        new FileReader("nonexistent");
    }
}

Output:

--- exec-maven-plugin:3.0.0:exec (default-cli) @ Test ---
Exception in thread "main" java.io.FileNotFoundException: nonexistent (The system cannot find the file specified)
	at java.base/java.io.FileInputStream.open0(Native Method)
	at java.base/java.io.FileInputStream.open(FileInputStream.java:216)
	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:111)
	at java.base/java.io.FileReader.<init>(FileReader.java:60)
	at com.acme.bugs.netbeans.StacktraceLink.main(StacktraceLink.java:10)

Clicking on a link starting with java.base/ (or any other Java module) does not open the file and a message Source file not found for "FileReader"/Source file not found for "FileInputStream" appears in the status bar.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows 10 64-bit

JDK

OpenJDK 18.0.2 Windows x64

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

Always happens with JDK 9+.

NetBeans is running on OpenJDK 18.0.2 and the project uses an OpenJDK 18.0.2 Maven toolchain. (Maven istself is running on Java 8, but that shouldn’t matter.)

NetBeans found the sources when adding the JDK 18.0.2 platform and these files can be opened in the Debugging tab when using the debugger. The links do not work even when the matching JDK file is opened.

I believe the links worked earlier when using Java 8 or older (without the module system).

The links work with own code and Maven dependencies (if the source JAR is present).

Are you willing to submit a pull request?

No

Code of Conduct

Yes

@maffe maffe added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Aug 18, 2022
@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) and removed needs:triage Requires attention from one of the committers labels Aug 18, 2022
@mbien
Copy link
Member

mbien commented Aug 18, 2022

Thanks for the detailed report. Could reproduce it on latest master too (basically NB 15).

@mbien
Copy link
Member

mbien commented Aug 18, 2022

btw as workaround you could paste the stack trace into the windows -> debugging -> analyze stack trace window.

It works from there.

@mbien mbien added this to the NB17 milestone Nov 14, 2022
@mbien mbien changed the title Links in stacktraces do not work (Source file not found) Links in output window stacktraces do not work (when java module system is used) Dec 12, 2022
@mbien mbien changed the title Links in output window stacktraces do not work (when java module system is used) Links in output window stacktraces do not work (when they point to JDK code) Dec 12, 2022
@neilcsmith-net
Copy link
Member

So looks like this code and the regex it uses need updating to be module aware - https://github.com/apache/netbeans/blob/master/java/maven/src/org/netbeans/modules/maven/api/output/OutputUtils.java#L172

See also regex in StackAnalyzer https://github.com/apache/netbeans/blob/master/java/java.navigation/src/org/netbeans/modules/java/stackanalyzer/StackLineAnalyser.java#L57

Would be good to have this in one place, but if not at least kept in sync? Anywhere else analyzing stack traces?

@neilcsmith-net neilcsmith-net added the Maven [ci] enable "build tools" tests label Dec 12, 2022
@mbien
Copy link
Member

mbien commented Dec 12, 2022

@neilcsmith-net there are multiple issues here I believe. If you set a breakpoint at

List<FileObject> resources = classPath.findAllResources(resourceName);
you see that the cp does not include the active JDK. So it doesn't find anything even if the parsing works.

This seems to be the case no matter if the project has a module info or not.

'packageName' a few lines above the breakpoint is incorrect too if a module is in the trace line (but this isn't the main issue).

edit: i renamed the title here to only track the issue of stack trace not being able to open jdk files, since I believe it will be easier to approach this incrementally.

@neilcsmith-net
Copy link
Member

@mbien yes, certainly didn't mean that the regex is the only issue that needs addressing in that code! It searches for the wrong package name with JDK missing from the classpath. Both are equally important, surely? Won't work with either broken. Project module info shouldn't be relevant to JDK classes being in a module. But module aware stack elements would also fix more than just the JDK links.

@mbien
Copy link
Member

mbien commented Dec 12, 2022

opening JDK links already didn't work on NB 8 + JDK 8 which indicates that it was most likely never implemented for maven projects. Going to take a look how to get the active jdk of a project and see how to proceed from there.

I already couldn't figure out how to get the project JDK info when I wrote #4802, lets give it another try.

@neilcsmith-net
Copy link
Member

@mbien yes, both are broken. I would guess lack of ClassPath.BOOT in the response at https://github.com/apache/netbeans/blob/master/java/maven/src/org/netbeans/modules/maven/api/output/OutputUtils.java#L244 ?

The stack trace analyzer doesn't work correctly here either, obviously, as it's just using the global classpath info, so always going to give the running JDK.

@errael
Copy link
Contributor

errael commented Dec 12, 2022

figure out how to get the project JDK info

Reminds me of what's going on sorting out gradle projects and which jdk... with #5052

@mbien
Copy link
Member

mbien commented Dec 14, 2022

forgot to post here that #5091 is pending and should fix the issue encountered here. dev build is linked from the PR. Would be good if someone could confirm that this issue is fixed.

@maehem
Copy link

maehem commented Dec 14, 2022 via email

@mbien
Copy link
Member

mbien commented Dec 14, 2022

@maehem awesome, thanks a lot for verifying!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:bug Bug report or fix Maven [ci] enable "build tools" tests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants