Skip to content

javac: java.lang.AssertionError: Unexpected tree error #6822

Closed

Description

@luvunix

Apache NetBeans version

Apache NetBeans 20 release candidate

What happened

Started NetBeans 20 and was notified of an exception.
messages.log
CollectionsCache_3.zip

How to reproduce

No response

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows 10

JDK

Microsoft JDK 17.0.9+8 (x64)

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

Experienced the issue in NetBeans 19 so updated to 20. Same issue occurred.

Are you willing to submit a pull request?

No

Activity

  1. added
    kind:bug
    needs:triage
    on Dec 9, 2023
  2. luvunix commented on Dec 9, 2023

    @luvunix
    Author

    Just realized that attempting to access Javadoc ([Ctrl]-mouse hover) in this specific source file does not work and throws this exception. It does not matter whether I am trying to access JavaDoc defined within the source file or within the JDK (e.g., attempting to access the Collections Javadoc).

  3. luvunix commented on Dec 9, 2023

    @luvunix
    Author

    Also, code completion works, but syntax errors are not highlighted.

  4. palaashatri commented on Dec 10, 2023

    @palaashatri

    Based on a quick overview of the error message (line 484 of log), it looks like the folder it's trying to access is already being read by some other thread, which has locked the files inside it..

    Are you running two instances of Netbeans, or is the file already under lock by some other process?

  5. luvunix commented on Dec 10, 2023

    @luvunix
    Author

    First, my apologies on how ugly the code is. I did not realize how much I depended on syntax highlighting. I cleaned the code up and then started playing around with it, seeing if I could find a way to trigger the error intentionally, and I did.

    What I found is that I can use the generic to declare the Collection and to get and set the collection. But the moment I change the parameter in the addEntry(), doesEntryExist(), and removeEntry() methods from a concrete class to the generic, the exception gets triggered and I lose syntax highlighting and Javadoc access.

    For example, the following declaration will not trigger the exception (although it does create an error in the method) :

    public boolean addEntry( String entry ) throws IllegalArgumentException

    Changing the declaration to the following then triggers the exception immediately:

    public boolean addEntry( <?> entry ) throws IllegalArgumentException

    Messages log and code attached. Thanks again for your help.

    messages.log
    CollectionsCache.zip

  6. added
    nb-javac
    on Dec 11, 2023
  7. mbien commented on Dec 11, 2023

    @mbien
    Member

    @luvunix if you would manage to create a small reproducer for this exception - that would be great. We might have to file this against OpenJDK.

    exception from the log for copy/paste convenience:

    Caused: java.lang.AssertionError: Unexpected tree: (ERROR) ? (ERROR) > entry : (ERROR) with kind: CONDITIONAL_EXPRESSION within: (ERROR) ? (ERROR) > entry : (ERROR) with kind: CONDITIONAL_EXPRESSION
    	at com.sun.tools.javac.util.Assert.error(Assert.java:162)
    	at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.validateAnnotatedType(Attr.java:5918)
    	at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitVarDef(Attr.java:5764)
    	at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1022)
    	at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
    	at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:58)
    	at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitMethodDef(Attr.java:5754)
    	at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:916)
    	at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
    	at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitClassDef(Attr.java:5817)
    	at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:814)
    	at com.sun.tools.javac.comp.Attr.validateTypeAnnotations(Attr.java:5714)
    	at com.sun.tools.javac.code.TypeAnnotations.lambda$validateTypeAnnotationsSignatures$1(TypeAnnotations.java:144)
    	at com.sun.tools.javac.comp.Annotate.flush(Annotate.java:200)
    	at com.sun.tools.javac.comp.Annotate.unblockAnnotations(Annotate.java:144)
    	at com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:157)
    	at com.sun.tools.javac.main.JavaCompiler.enterDone(JavaCompiler.java:1820)
    	at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:1074)
    	at com.sun.tools.javac.api.JavacTaskImpl.enter(JavacTaskImpl.java:345)
    	at com.sun.tools.javac.api.JavacTaskImpl.enter(JavacTaskImpl.java:282)
    	at org.netbeans.modules.java.source.parsing.JavacParser.moveToPhase(JavacParser.java:748)
    	at org.netbeans.modules.java.source.parsing.JavacParser.getResult(JavacParser.java:541)
    	at org.netbeans.modules.java.source.parsing.JavacParser.getResult(JavacParser.java:142)
    	at org.netbeans.modules.parsing.impl.TaskProcessor.callGetResult(TaskProcessor.java:608)
    	at org.netbeans.modules.parsing.impl.SourceCache.getResult(SourceCache.java:241)
    	at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.run(TaskProcessor.java:775)
    	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:288)
    	at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.execute(TaskProcessor.java:702)
    [catch] at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:663)
    	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1420)
    	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
    	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
    	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2035)
    
  8. added
    Java
    and removed
    needs:triage
    on Dec 11, 2023
  9. luvunix commented on Dec 11, 2023

    @luvunix
    Author

    As requested (if I am understanding the request). Create an class with the following method:

    public void addEntry( <?> entry ) {
    // "<?> in the parameter declaration triggers the bug
    }

    Change the "" to "String", and things are normal. Change back to "" and the exception is triggered immediately.

    If I misunderstood the request let me know and I'll try again.

    Thank you once again!

  10. changed the title [-]java.lang.AssertionError: Unexpected tree error[/-] [+]javac: java.lang.AssertionError: Unexpected tree error[/+] on Dec 19, 2023
  11. mbien commented on Aug 5, 2024

    @mbien
    Member

    I checked and this is still reproducible in NB 23 rc1. Since the the code is invalid (type is missing) and it seems to be specific to method params this particular scenario will hopefully rarely happen out in the wild.

  12. added this to the NB29 milestone on Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Javakind:bugnb-javac

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions