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 201730

Summary: NullPointerException at org.netbeans.api.java.source.GeneratorUtilities.addImports
Product: java Reporter: Vladimir Riha <vriha>
Component: CompilerAssignee: Dusan Balek <dbalek>
Status: VERIFIED FIXED    
Severity: normal CC: jglick, vriha
Priority: P2 Keywords: REGRESSION
Version: 7.0   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter: 181003
Bug Depends on:    
Bug Blocks: 122109    
Attachments: stacktrace

Description Vladimir Riha 2011-09-07 09:36:12 UTC
Build: NetBeans IDE Dev (Build 201109060600)
VM: Java HotSpot(TM) Client VM, 21.0-b17, Java(TM) SE Runtime Environment, 1.7.0-b147
OS: Linux

User Comments:
vriha: Reproducible...

Steps to reproduce:
- create new Java Web project
- invoke new File dialog, select Web Services and "RESTful web services from Patterns", next
- select "Container-Item", next
- type some package name

The exception was thrown either after pressing Finish or after confirming the next opened dialog (REST Resources Configuration)




Stacktrace: 
java.lang.NullPointerException
   at org.netbeans.api.java.source.GeneratorUtilities.addImports(GeneratorUtilities.java:615)
   at org.netbeans.modules.java.source.transform.ImmutableTreeTranslator.rewriteChildren(ImmutableTreeTranslator.java:525)
   at org.netbeans.modules.java.source.transform.ImmutableTreeTranslator.visitCompilationUnit(ImmutableTreeTranslator.java:332)
   at org.netbeans.modules.java.source.transform.ImmutableTreeTranslator.visitCompilationUnit(ImmutableTreeTranslator.java:92)
   at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:490)
   at org.netbeans.modules.java.source.transform.ImmutableTreeTranslator.translate(ImmutableTreeTranslator.java:134)
Comment 1 Vladimir Riha 2011-09-07 09:36:16 UTC
Created attachment 110467 [details]
stacktrace
Comment 2 Vladimir Riha 2011-09-07 09:37:38 UTC
Update: Exception is thrown after I confirm the "REST Resources Configuration" dialog which appears right after pressing Finish button
Comment 3 Dusan Balek 2011-09-07 15:08:36 UTC
Fixed in jet-main.

http://hg.netbeans.org/jet-main/rev/15bd6072f5fc
Comment 4 Jesse Glick 2011-09-07 15:24:29 UTC
Seems to completely break "Use @NbBundle.Messages" hint.
Comment 5 Jesse Glick 2011-09-07 15:36:18 UTC
http://statistics.netbeans.org/exceptions/messageslog?id=526667 is the same stack trace but when running with the purported fix.
Comment 6 Jesse Glick 2011-09-07 16:08:29 UTC
getImportedElement returns null on the static wildcard import.


By the way this code (run later, after the bug occurs) is probably wrong:

                for (Element e : parent.getEnclosedElements()) {
                    if (name == e.getSimpleName() && e.getModifiers().contains(Modifier.STATIC) && trees.isAccessible(s, e, (DeclaredType)parent.asType()));
                        return e;
                }

You do some test and then ignore the result and return the first enclosed element unconditionally. Noticed because indentation does not match reality. Delete the stray semicolon.
Comment 7 Jesse Glick 2011-09-07 16:11:55 UTC
imp is e.g. "import static pkg.Bundle.*;\n" with qualIdent "pkg.Bundle.*" of kind IDENTIFIER.
Comment 8 Jesse Glick 2011-09-07 16:22:12 UTC
I tried something like this:

String qualIdentS = qualIdent.toString();
if (qualIdentS.endsWith(".*")) {
    String fqn = qualIdentS.substring(0, qualIdentS.length() - 2);
    element = elements.getTypeElement(fqn);
    if (element == null) {
        element = elements.getPackageElement(fqn);
    }
    return element;
}

but it does not help; fqn "pkg.Bundle" is not yet available in elements, because it will be created by an AP only after the file has been saved.
Comment 9 Jesse Glick 2011-09-07 16:32:48 UTC
BTW to reproduce, simply create a new standalone module, add a custom wizard iterator with one panel, find one of the NbBundle.getMessage calls, and accept the hint on it.
Comment 10 Jesse Glick 2011-09-08 11:53:48 UTC
Only known workaround is to use 7.0.1 for this hint.
Comment 11 Dusan Balek 2011-09-08 13:35:14 UTC
OOPS - second attempt

http://hg.netbeans.org/jet-main/rev/0c6b5cd053df

Jesse thanks for your investigation.
Comment 12 Quality Engineering 2011-09-08 14:27:24 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/15bd6072f5fc
User: Dusan Balek <dbalek@netbeans.org>
Log: Issue #201730: NullPointerException at org.netbeans.api.java.source.GeneratorUtilities.addImports - fixed.
Comment 13 Quality Engineering 2011-09-09 15:00:58 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/0c6b5cd053df
User: Dusan Balek <dbalek@netbeans.org>
Log: Issue #201730: NullPointerException at org.netbeans.api.java.source.GeneratorUtilities.addImports - fix cont.
Comment 14 Vladimir Riha 2011-09-12 06:19:18 UTC
verified