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 122827 - [model] The model throws NPE when there is a switch statement in the code
Summary: [model] The model throws NPE when there is a switch statement in the code
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Code (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Denis Anisimov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-27 09:26 UTC by Tomasz Slota
Modified: 2007-12-04 13:48 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tomasz Slota 2007-11-27 09:26:48 UTC
Steps to reproduce:

Create a new PHP page. In the PHP area type swi and use the code completion to create a switch statement (second code completion item). The following 
NPE is thrown:

java.lang.NullPointerException
	at org.netbeans.modules.php.model.impl.SourceElementImpl.createChildrenList(SourceElementImpl.java:200)
	at org.netbeans.modules.php.model.impl.SourceElementImpl.initChildren(SourceElementImpl.java:225)
	at org.netbeans.modules.php.model.impl.SourceElementImpl.getChildren(SourceElementImpl.java:133)
	at org.netbeans.modules.php.editor.formatting.PHPFormatter.processSourceElement(PHPFormatter.java:328)
	at org.netbeans.modules.php.editor.formatting.PHPFormatter.processSourceElement(PHPFormatter.java:329)
	at org.netbeans.modules.php.editor.formatting.PHPFormatter.processSourceElement(PHPFormatter.java:329)
	at org.netbeans.modules.php.editor.formatting.PHPFormatter.processStatementList(PHPFormatter.java:313)
	at org.netbeans.modules.php.editor.formatting.PHPFormatter.reformat(PHPFormatter.java:216)
	at org.netbeans.modules.php.editor.formatting.PHPFormatter.reformat(PHPFormatter.java:121)
	at org.netbeans.modules.php.editor.formatting.PHPFormatter.process(PHPFormatter.java:116)
	at org.netbeans.modules.php.editor.formatting.EmbeddedPHPIndentTask.reindent(EmbeddedPHPIndentTask.java:49)
	at org.netbeans.modules.editor.indent.TaskHandler$MimeItem.runTask(TaskHandler.java:498)
	at org.netbeans.modules.editor.indent.TaskHandler.runTasks(TaskHandler.java:267)
	at org.netbeans.modules.editor.indent.IndentImpl.reformat(IndentImpl.java:285)
	at org.netbeans.modules.editor.indent.FormatterImpl.reformat(FormatterImpl.java:161)
	at org.netbeans.lib.editor.codetemplates.CodeTemplateInsertHandler.insertTemplate(CodeTemplateInsertHandler.java:354)
	at org.netbeans.lib.editor.codetemplates.CodeTemplateInsertHandler.processTemplate(CodeTemplateInsertHandler.java:264)
	at org.netbeans.lib.editor.codetemplates.CodeTemplateManagerOperation.insert(CodeTemplateManagerOperation.java:244)
	at org.netbeans.lib.editor.codetemplates.api.CodeTemplate.insert(CodeTemplate.java:100)
	at org.netbeans.lib.editor.codetemplates.CodeTemplateCompletionItem.defaultAction(CodeTemplateCompletionItem.java:122)
	at org.netbeans.modules.editor.completion.CompletionImpl.dispatchKeyEvent(CompletionImpl.java:543)
	at org.netbeans.modules.editor.completion.CompletionImpl.keyPressed(CompletionImpl.java:347)
	at java.awt.AWTEventMulticaster.keyPressed(AWTEventMulticaster.java:192)

The same happens when the user calls reformat and probably in other situations when the model needs to be refreshed.
Comment 1 Denis Anisimov 2007-11-27 13:12:02 UTC
There is a problem with statements list AST node.
It can be empty but this case is not handled correctly in OM impl.
Comment 2 Denis Anisimov 2007-12-04 13:48:44 UTC
Fixed.

    Checking in php/srcmodel/src/org/netbeans/modules/php/model/impl/FactoryVisitor.java;
    /cvs/scripting/php/srcmodel/src/org/netbeans/modules/php/model/impl/FactoryVisitor.java,v  <--  FactoryVisitor.java
    new revision: 1.27; previous revision: 1.26
    done
    Removing php/srcmodel/src/org/netbeans/modules/php/model/impl/factory/StatementsFactory.java;
    /cvs/scripting/php/srcmodel/src/org/netbeans/modules/php/model/impl/factory/StatementsFactory.java,v  <-- 
StatementsFactory.java
    new revision: delete; previous revision: 1.4
    done