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

Disassembled *.class opened instead of *.java when folder with name of class exists in sources JAR #5738

Closed
jglick opened this issue Mar 29, 2023 · 2 comments · Fixed by #5739
Assignees
Labels
Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:bug Bug report or fix Regression This used to work!
Milestone

Comments

@jglick
Copy link
Contributor

jglick commented Mar 29, 2023

Apache NetBeans version

Apache NetBeans 17

What happened

When you have a Maven sources JAR present in the local repository, confirmed by SourceForBinaryQuery via apisupport.projectinspector¹, then visiting a type or member in the classpath should open the editor on a read-only source file. In NB 16 this used to work consistently. In 17 it sometimes works, but sometimes you get the disassembled bytecode instead. I am still working out the precise conditions for the bug, since it happens on some types in a single JAR file and not others.


¹Sadly abandoned in contrib Hg rather than donated, AFAICT, but I still have a personal copy.

How to reproduce

git clone https://github.com/jenkinsci/log-cli-plugin
cd log-cli-plugin
mvn -Pquick-build package dependency:sources

Now open this project in NB and wait for classpath scanning to complete. At https://github.com/jenkinsci/log-cli-plugin/blob/3d86457a9f2b19567d90542074224416a9ca474c/src/main/java/org/jenkinsci/plugins/log_cli/TailLogCommand.java#L55 place the caret on the call to get and press Ctrl-B to visit the definition.

Expected: you should see https://github.com/jenkinsci/jenkins/blob/jenkins-2.361.4/core/src/main/java/jenkins/model/Jenkins.java#L810

Actual: you will see disassembled bytecode

    @NonNull
    public static Jenkins get() throws IllegalStateException {
        // <editor-fold defaultstate="collapsed" desc="Compiled Code">
        /* 0: invokestatic  #8                  // Method getInstanceOrNull:()Ljenkins/model/Jenkins;
         * 3: astore_0
         * 4: aload_0
         * 5: ifnonnull     18
         * 8: new           #9                  // class java/lang/IllegalStateException
         * 11: dup
         * 12: ldc           #10                 // String Jenkins.instance is missing. Read the documentation of Jenkins.getInstanceOrNull to see what you are doing wrong.
         * 14: invokespecial #11                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
         * 17: athrow
         * 18: aload_0
         * 19: areturn
         *  */
        // </editor-fold>
    }

Note that if on the same line of source you instead click on the next method call, checkPermission, you are correctly taken to https://github.com/jenkinsci/jenkins/blob/jenkins-2.361.4/core/src/main/java/hudson/security/AccessControlled.java#L48 from ~/.m2/repository/org/jenkins-ci/main/jenkins-core/2.361.4/jenkins-core-2.361.4-sources.jar.

Did this work correctly in an earlier version?

Apache NetBeans 16

Operating System

Xubuntu 22.04.2

JDK

11.0.18; OpenJDK 64-Bit Server VM 11.0.18+10-post-Ubuntu-0ubuntu122.04; Ubuntu

Apache NetBeans packaging

Apache NetBeans Snap Package

Anything else

Using git bisect I was able to identify #5152 (@jtulach) as the cause of the regression. This does not appear to be a duplicate of #5266, which apparently involved a visible exception (no error is printed in this case) and which was allegedly fixed in NB 17 in #5279 (@matthiasblaesing).

I hope to find time to study the bug and offer a PR, since this affects everyday usage of the IDE for me and is the one noticeable regression in NB 17.

Are you willing to submit a pull request?

Yes

@jglick jglick added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Mar 29, 2023
@jglick
Copy link
Contributor Author

jglick commented Mar 29, 2023

Also can be reproduced after opening the project just by browsing inside jenkins-core-2.361.4.jar in the Projects tab and clicking on different *.class entries. Some open sources, some do not. When it does not work, the log notes

WARNING [org.netbeans.modules.java.ClassDataObject]: SourceFile: hudson/console/ExpandableDetailsNote in ~/.m2/repository/org/jenkins-ci/main/jenkins-core/2.361.4/jenkins-core-2.361.4.jar has no OpenCookie

The lack of a .java extension on this resource leads me to suspect that

resource = SourceUtils.getFile(handle, ClasspathInfo.create(
ClassPathSupport.createClassPath(binaryRoot),
ClassPath.EMPTY,
ClassPath.EMPTY));
is receiving a bogus result. Indeed the problem seems to occur on classes which have associated resources (the naming convention here is specific to Jenkins and its github.com/jenkinsci/stapler framework):

$ jar tf ~/.m2/repository/org/jenkins-ci/main/jenkins-core/2.361.4/jenkins-core-2.361.4-sources.jar | fgrep ExpandableDetailsNote
hudson/console/ExpandableDetailsNote/
hudson/console/ExpandableDetailsNote.java
hudson/console/ExpandableDetailsNote/style.css
hudson/console/ExpandableDetailsNote/script.js

@neilcsmith-net
Copy link
Member

Reminds me a little of #2115 Putting a milestone on this to track for NB18.

@neilcsmith-net neilcsmith-net removed the needs:triage Requires attention from one of the committers label Mar 29, 2023
@neilcsmith-net neilcsmith-net added this to the NB18 milestone Mar 29, 2023
@neilcsmith-net neilcsmith-net added the Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) label Mar 29, 2023
@jglick jglick self-assigned this Mar 29, 2023
@jglick jglick changed the title Disassembled *.class opened instead of *.java even when Maven *-sources.jar present Disassembled *.class opened instead of *.java when corresponding folder exists in sources JAR Mar 29, 2023
@jglick jglick changed the title Disassembled *.class opened instead of *.java when corresponding folder exists in sources JAR Disassembled *.class opened instead of *.java when correspondingly named folder exists in sources JAR Mar 29, 2023
@jglick jglick changed the title Disassembled *.class opened instead of *.java when correspondingly named folder exists in sources JAR Disassembled *.class opened instead of *.java when folder with name of class exists in sources JAR Mar 29, 2023
@jglick jglick added the Regression This used to work! label Mar 29, 2023
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 Regression This used to work!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants