Skip to content

NPE on annotation processing #8722

Closed

Description

@hajdam

Apache NetBeans version

Apache NetBeans 27 latest release candidate

What happened

When using @SuppressWarnings annotation (without any braces parameter)

Caused: java.lang.NullPointerException: Cannot read field "values" because "values" is null
	at com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:383)
	at org.netbeans.modules.java.source.parsing.JavacParser.moveToPhase(JavacParser.java:765)
...

java_1.dump.log

Language / Project Type / NetBeans Component

No response

How to reproduce

Start clean NetBeans 27-rc3
File/New File
Other/Java file
File name: Test
To static main method add annotation: @SuppressWarnings
Save file

Did this work correctly in an earlier version?

Apache NetBeans 26

Operating System

Fedora 41 Linux version 6.15.9-101.fc41.x86_64 running on amd64; UTF-8;

JDK

Oracle JDK 17.0.15; Java HotSpot(TM) 64-Bit Server VM 17.0.15+9-LTS-24

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

No

Activity

  1. added
    kind:bug
    needs:triage
    on Aug 9, 2025
  2. added
    Java
    and removed
    needs:triage
    on Aug 10, 2025
  3. matthiasblaesing commented on Aug 10, 2025

    @matthiasblaesing
    Contributor

    @lahodaj this is reproducible and looks like a problem in the Linter. Would you mind having a look?

    I got this in the IDE:

    Caused: java.lang.NullPointerException: Cannot read field "values" because "values" is null
    	at com.sun.tools.javac.code.Lint.suppressionsFrom(Lint.java:532)
    	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:215)
    	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:197)
    	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
    

    Looking at the code in:

    https://github.com/openjdk/jdk/blob/022e29a77533aacabd56820d00ecffa9646a8362/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java#L528-L541

    there is a null check missing.

    That code breaks independent from the IDE (tested with Build 35 (2025/8/8)):

    @SuppressWarnings
    public class TestX {
        public static void main(String[] args) {
        }
    }
    matthias@enterprise:~/NetBeansProjects/MavenSpielwiese/src/main/java$ LANG=C ~/bin/jdk-25/bin/javac -XDshould-stop.at=FLOW -XDdev Test.java                                                             
    Test.java:2: error: annotation @SuppressWarnings is missing a default value for the element 'value'                                                                                                     
    @SuppressWarnings                                                                                                                                                                                       
    ^                                                                                                                                                                                                       
    1 error                                                                                                                                                                                                 
    An exception has occurred in the compiler (25). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.                                                      
    java.lang.NullPointerException: Cannot read field "values" because "values" is null                                                                                                                     
            at jdk.compiler/com.sun.tools.javac.code.Lint.suppressionsFrom(Lint.java:532)                                                                                                                   
            at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)                                                                                                          
            at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:197)                                                                                                          
            at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)                                                                                                                             
            at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1939)                                                                                                
            at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)                                                                                                              
            at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)                                                                                                       
            at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:153)                                                                                                      
            at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:176)                                                                                                
            at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)                                                                                                              
            at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:632)                                                                                                             
            at jdk.compiler/com.sun.tools.javac.code.Lint.suppressionsFrom(Lint.java:524)                                                                                                                   
            at jdk.compiler/com.sun.tools.javac.code.Lint.suppressionsFrom(Lint.java:511)                                                                                                                   
            at jdk.compiler/com.sun.tools.javac.code.Lint.augment(Lint.java:82)                                                                                                                             
            at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5414)                                                                                                                       
            at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5365)                                                                                                                       
            at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5302)                                                                                                                            
            at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1346)                                                                                                         
            at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:968)                                                                                                            
            at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:319)                                                                                                                            
            at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:178)                                                                                                                            
            at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:66)                                                                                                                                  
            at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:52)                                                                                                                                     
    printing javac parameters to: /tmp/javac.20250810_151958.args                                                                                                                                           
    matthias@enterprise:~/NetBeansProjects/MavenSpielwiese/src/main/java$
    
  4. added
    nb-javac
    on Aug 10, 2025
  5. lahodaj commented on Aug 12, 2025

    @lahodaj
    Contributor
  6. mbien commented on Aug 14, 2025

    @mbien
    Member

    will put NB 28 on this issue since its too late for NB 27 most likely (I don't think more RCs are planned and the nb-javac + patch roundtrip would take time and require someone who would want to do that).

    Workaround (for users) would be to help javac by adding ("") to the annotation, this allows auto-completion.

    Assuming JDK-8365314 will be in JDK 25.0.1, NB 27 could be also run on JDK 25 with nb-javac uninstalled, but by that time NB 28 wouldn't be far away anymore.

  7. added this to the NB28 milestone on Aug 14, 2025
  8. neilcsmith-net commented on Aug 18, 2025

    @neilcsmith-net
    Member

    Well, this bug is a shame and somewhat annoying! I'm not sure it's useful to be showing the error notification for a bunch of parsing errors we currently have.

    I've looked at part of this stack trace before with another bug. As well as this being a JDK issue, I'm curious at the behaviour of JavacParser::moveToPhase. This method is documented to throw an IOException when javac throws any exception here but doesn't do so. This means it bypasses the catch that throws a ParseException here. Is that intentional behaviour?

    EDIT : I'm not sure that would change the exception being reported in this particular case. I do question which exceptions are meant to be used, and which should be reported in the UI vs logging.

  9. mbien commented on Aug 18, 2025

    @mbien
    Member

    IMO: trying to hide exceptions is the wrong approach, particularly with javac problems since it is not possible to tell what the consequence of the failure is. It can cause error badges in files when the parser gives up, it can cause a refactoring failure or it cause completion to not work.

    I get that exceptions also happen while typing which can be harmless, but trying to filter those out might not be worth the efforts and cause obfuscation of the above mentioned issues.

  10. neilcsmith-net commented on Aug 18, 2025

    @neilcsmith-net
    Member

    That kind of misses my point. The parsing code already filters by exception types in a bunch of places. Javacparser doesn't seem to follow its own documented behaviour.

  11. mbien commented on Aug 18, 2025

    @mbien
    Member

    We can try to tweak exception handling a bit so that error badges can show up on the file using this as test scenario. But there is only so much we can do with exception handling before javac has to be fixed.

    Hiding javac exceptions was brought up before, I only wanted to reiterate that I don't think this would be a good idea, those are real problems in many cases.

  12. mbien commented on Aug 18, 2025

    @mbien
    Member

    added mbien/nb-reprorepo@0696a1a to simplify testing

  13. neilcsmith-net commented on Aug 18, 2025

    @neilcsmith-net
    Member

    We shouldn't be hiding javac exceptions. Whether it should be a log or UI message is somewhat open to debate. That's a secondary question.

    I'm first trying to understand why JavacParser is not throwing the exception it states it does, and what the consequences of or decision behind that is? Is it deliberate?

  14. mbien commented on Aug 18, 2025

    @mbien
    Member

    Whether it should be a log or UI message is somewhat open to debate. That's a secondary question.

    both, since it increases the chances that we get an reproducer for harder to find issues. It also helps to connect symptoms with issues for users "completion didn't work, ah I see a red marker in the bottom corner".

    I'm first trying to understand why JavacParser is not throwing the exception it states it does, and what the consequences of or decision behind that is? Is it deliberate?

    i don't know. But if changing it would give us error markers in files when comparable issues occur it would be something to consider.

  15. modified the milestones: NB28, NB29 on Nov 6, 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

    JDK bugJavakind:bugnb-javac

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions