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 198325 - CompletionUtil.isDTDBasedDocument NullPointerException
Summary: CompletionUtil.isDTDBasedDocument NullPointerException
Status: RESOLVED WONTFIX
Alias: None
Product: xml
Classification: Unclassified
Component: Schema Tools (show other bugs)
Version: 7.0
Hardware: All All
: P4 normal with 2 votes (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-04 20:48 UTC by jsmith5and5
Modified: 2016-07-07 09:56 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
plattform properties for my app (5.29 KB, application/octet-stream)
2011-07-20 16:07 UTC, ma.schroed
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jsmith5and5 2011-05-04 20:48:59 UTC
Stack trace below. See <----- NullPointerException for line.

 public static boolean isDTDBasedDocument(Document document) {
        ((AbstractDocument)document).readLock();
        try {
            TokenHierarchy th = TokenHierarchy.get(document);
            TokenSequence ts = th.tokenSequence();
            while(ts.moveNext()) {                <----- NullPointerException here
                Token token = ts.token();

The solution is obvious: put in a check for "if (ts != null)" before the while loop and allow the method to return false.

You can see from the source of TokenHierarchy.tokenSequence that null is a reasonable return value.

------------------------------


java.lang.NullPointerException
	at org.netbeans.modules.xml.schema.completion.util.CompletionUtil.isDTDBasedDocument(CompletionUtil.java:669)
	at org.netbeans.modules.xml.schema.completion.util.CompletionUtil.canProvideCompletion(CompletionUtil.java:769)
	at org.netbeans.modules.xml.schema.completion.SchemaBasedCompletionProvider.getAutoQueryTypes(SchemaBasedCompletionProvider.java:80)
	at org.netbeans.modules.editor.completion.CompletionImpl.insertUpdate(CompletionImpl.java:320)
	at org.netbeans.lib.editor.util.swing.PriorityDocumentListenerList.insertUpdate(PriorityDocumentListenerList.java:85)
	at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:185)
	at org.netbeans.editor.BaseDocument.fireInsertUpdate(BaseDocument.java:1670)
	at org.netbeans.editor.BaseDocument.insertString(BaseDocument.java:816)
	at org.netbeans.editor.BaseKit$DefaultKeyTypedAction.insertString(BaseKit.java:1198)
	at org.netbeans.editor.BaseKit$DefaultKeyTypedAction.performTextInsertion(BaseKit.java:1264)
	at org.netbeans.editor.BaseKit$DefaultKeyTypedAction.access$100(BaseKit.java:1077)
	at org.netbeans.editor.BaseKit$DefaultKeyTypedAction$1.run(BaseKit.java:1137)
	at org.netbeans.editor.GuardedDocument.runAtomicAsUser(GuardedDocument.java:344)
	at org.netbeans.editor.BaseKit$DefaultKeyTypedAction.actionPerformed(BaseKit.java:1130)
	at org.netbeans.editor.ext.ExtKit$ExtDefaultKeyTypedAction.actionPerformed(ExtKit.java:1068)
	at org.netbeans.editor.BaseAction.actionPerformed(BaseAction.java:339)
	at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1633)
	at javax.swing.JComponent.processKeyBinding(JComponent.java:2851)
	at javax.swing.JComponent.processKeyBindings(JComponent.java:2886)
	at javax.swing.JComponent.processKeyEvent(JComponent.java:2814)
	at java.awt.Component.processEvent(Component.java:6040)
	at java.awt.Container.processEvent(Container.java:2041)
	at java.awt.Component.dispatchEventImpl(Component.java:4630)
	at java.awt.Container.dispatchEventImpl(Container.java:2099)
	at java.awt.Component.dispatchEvent(Component.java:4460)
	at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:712)
	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:990)
	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:855)
	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:676)
	at java.awt.Component.dispatchEventImpl(Component.java:4502)
	at java.awt.Container.dispatchEventImpl(Container.java:2099)
	at java.awt.Window.dispatchEventImpl(Window.java:2478)
	at java.awt.Component.dispatchEvent(Component.java:4460)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:148)
[catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Comment 1 jsmith5and5 2011-05-05 13:16:52 UTC
I also should have noted that this occurred when making a NetBeans Platform application therefore it may not show up in NetBeans IDE.
Comment 2 ma.schroed 2011-07-20 16:07:42 UTC
Created attachment 109538 [details]
plattform properties for my app
Comment 3 ma.schroed 2011-07-20 16:08:44 UTC
This happens when "Schema Aware Code Completion" in a Plattform Application is enabled.
Comment 4 macrominds 2011-09-28 10:51:49 UTC
The described bug is a bug and should be corrected, no doubt. 

I just want to leave a hint on the cause of the NullpointerException:

The reason why tokenSequence (line 668 in CompletionUtil) returns null (and leads to the NullpointerException in 669) is, that there's no appropriate LanguageProvider registered in your case. I'd bet that you missed to add a Dependency to org.getbeans.modules : org-netbans-modules-lexer-nbbridge, which provides the org.netbeans.modules.lexer.nbbridge.MimeLookupLanguageProvider.

Just found that out on a long trial-error-journey through loads of Netbeans-Modules. It seems to be awfully complicated to integrate a schema-aware XMLEditor in a standalone app.
Comment 5 jsmith5and5 2011-09-28 12:58:37 UTC
Hi, thanks for your help.

You're right about the root cause being the missing org-netbans-modules-lexer-nbbridge dependency. As far as that goes, I think a problem with the way the module system works is that some of the modules are implementation only (which in itself is fine) but that when you add a dependency to get an XML editor, etc. it picks up the API (interface) modules as being required but no implementation. You don't need any particular implementation or more than one, but you do need one for things to work.

By NetBeans Platform application I didn't mean a standalone app, I meant it's not the IDE itself. It's still a regular, bona-fide NetBeans Platform application using the module system, etc.
Comment 6 Martin Balin 2016-07-07 09:56:59 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss