| Summary: | NPE using ElementImpl.getAttribute(String) | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [WebTools] WTP Source Editing | Reporter: | Alessandro Carraro <carraro.alessandro> | ||||
| Component: | wst.xml | Assignee: | Nitin Dahyabhai <thatnitind> | ||||
| Status: | RESOLVED FIXED | QA Contact: | Nitin Dahyabhai <thatnitind> | ||||
| Severity: | major | ||||||
| Priority: | P2 | CC: | carraro.alessandro, david_fire4, eclipse, eclipse, GivenRandy, marco.gulino, mathiastck, nsand.dev, pgrondal, remy.suen, tango17, xjivan | ||||
| Version: | unspecified | Flags: | thatnitind:
pmc_approved?
(david_williams) thatnitind: pmc_approved? (raghunathan.srinivasan) thatnitind: pmc_approved? (naci.dai) deboer: pmc_approved+ thatnitind: pmc_approved? (neil.hauge) thatnitind: pmc_approved? (kaloyan) nsand.dev: review+ |
||||
| Target Milestone: | 3.2.2 | ||||||
| Hardware: | All | ||||||
| OS: | All | ||||||
| URL: | http://groups.google.com/group/android-developers/browse_thread/thread/5ea69f7367b725a5 | ||||||
| Whiteboard: | PMC_approved | ||||||
| Attachments: |
|
||||||
A stack trace would be very useful for this. Possibly caused by org.eclipse.wst.xml.core.internal.contentmodel.basic.CMAttributeDeclarationImpl.CMAttributeDeclarationImpl(String, int) not supplying a CMDataType object, which is required not to be null. Created attachment 172860 [details]
proposed patch with JUnit
Here is the XML: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello, Android! I am a string resource!</string> <string name="app_name">Hello, Android</string> </resources> This is the "Android Xml Resources Editor" !STACK 0 java.lang.NullPointerException at org.eclipse.wst.xml.core.internal.document.ElementImpl.getDefaultValue(ElementImpl.java:259) at org.eclipse.wst.xml.core.internal.document.ElementImpl.getAttributeNS(ElementImpl.java:329) at com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode.getShortDescription(Unknown Source) at com.android.ide.eclipse.adt.internal.editors.ui.tree.UiModelTreeLabelProvider.getText(Unknown Source) at org.eclipse.jface.viewers.WrappedViewerLabelProvider.getText(WrappedViewerLabelProvider.java:108) at org.eclipse.jface.viewers.WrappedViewerLabelProvider.update(WrappedViewerLabelProvider.java:164) at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:152) at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:934) at org.eclipse.jface.viewers.AbstractTreeViewer$UpdateItemSafeRunnable.run(AbstractTreeViewer.java:102) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49) at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175) at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:1014) at org.eclipse.jface.viewers.StructuredViewer$UpdateItemSafeRunnable.run(StructuredViewer.java:481) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49) at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175) at org.eclipse.jface.viewers.StructuredViewer.updateItem(StructuredViewer.java:2141) at org.eclipse.jface.viewers.AbstractTreeViewer.updateChildren(AbstractTreeViewer.java:2689) at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefreshStruct(AbstractTreeViewer.java:1867) at org.eclipse.jface.viewers.TreeViewer.internalRefreshStruct(TreeViewer.java:721) at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefresh(AbstractTreeViewer.java:1842) at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefresh(AbstractTreeViewer.java:1799) at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefresh(AbstractTreeViewer.java:1785) at org.eclipse.jface.viewers.StructuredViewer$7.run(StructuredViewer.java:1487) at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1422) at org.eclipse.jface.viewers.TreeViewer.preservingSelection(TreeViewer.java:403) at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1383) at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1485) at org.eclipse.jface.viewers.ColumnViewer.refresh(ColumnViewer.java:537) at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1444) at com.android.ide.eclipse.adt.internal.editors.ui.tree.UiTreeBlock$2.uiElementNodeUpdated(Unknown Source) at com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode.invokeUiUpdateListeners(Unknown Source) at com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode.loadFromXmlNode(Unknown Source) at com.android.ide.eclipse.adt.internal.editors.resources.ResourcesEditor.xmlModelChanged(Unknown Source) at com.android.ide.eclipse.adt.internal.editors.AndroidEditor$XmlModelStateListener.modelChanged(Unknown Source) at org.eclipse.wst.sse.core.internal.model.AbstractStructuredModel.fireModelChanged(AbstractStructuredModel.java:553) at org.eclipse.wst.sse.core.internal.model.AbstractStructuredModel.internalModelChanged(AbstractStructuredModel.java:887) at org.eclipse.wst.sse.core.internal.model.AbstractStructuredModel.changedModel(AbstractStructuredModel.java:382) at org.eclipse.wst.xml.core.internal.document.DOMModelImpl.changedModel(DOMModelImpl.java:167) at org.eclipse.wst.sse.ui.StructuredTextEditor.savedModel(StructuredTextEditor.java:2814) at org.eclipse.wst.sse.ui.StructuredTextEditor.doSave(StructuredTextEditor.java:1826) at com.android.ide.eclipse.adt.internal.editors.AndroidEditor.doSave(Unknown Source) at org.eclipse.ui.internal.SaveableHelper$2.run(SaveableHelper.java:151) at org.eclipse.ui.internal.SaveableHelper$5.run(SaveableHelper.java:277) at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464) at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372) at org.eclipse.jface.window.ApplicationWindow$1.run(ApplicationWindow.java:759) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70) at org.eclipse.jface.window.ApplicationWindow.run(ApplicationWindow.java:756) at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2600) at org.eclipse.ui.internal.SaveableHelper.runProgressMonitorOperation(SaveableHelper.java:285) at org.eclipse.ui.internal.SaveableHelper.runProgressMonitorOperation(SaveableHelper.java:264) at org.eclipse.ui.internal.SaveableHelper.savePart(SaveableHelper.java:156) at org.eclipse.ui.internal.EditorManager.savePart(EditorManager.java:1369) at org.eclipse.ui.internal.WorkbenchPage.savePart(WorkbenchPage.java:3334) at org.eclipse.ui.internal.WorkbenchPage.saveEditor(WorkbenchPage.java:3347) at org.eclipse.ui.internal.SaveAction.run(SaveAction.java:76) at org.eclipse.jface.action.Action.runWithEvent(Action.java:498) at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:185) at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:109) at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476) at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508) at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:468) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:786) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:885) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:567) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:508) at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:123) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1253) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062) at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1103) at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1099) at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1508) at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:4268) at org.eclipse.swt.widgets.Canvas.WM_CHAR(Canvas.java:345) at org.eclipse.swt.widgets.Control.windowProc(Control.java:4160) at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4873) at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method) at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2459) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3655) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427) at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574) at org.eclipse.equinox.launcher.Main.run(Main.java:1407) *** Bug 320183 has been marked as a duplicate of this bug. *** Since mine was marked a duplicate of this, just want to make sure -- so this would cause NPEs when just editing resource files like "strings.xml"? Everytime you type a character or delete/backspace? (In reply to comment #6) > Since mine was marked a duplicate of this, just want to make sure -- so this > would cause NPEs when just editing resource files like "strings.xml"? Everytime > you type a character or delete/backspace? Inside an attribute value, yes. As a workaround, go to the XML/XML Files/Editor preference page and turn off the "Use inferred grammar..." setting. An NPE is triggered by a flaw in the inferred grammar support, causing problems editing XML files when it's enabled. The only workaround is to disable the inferred grammar support, but then the entire functionality is lost. Fix and JUnit are attached. Released. *** Bug 321759 has been marked as a duplicate of this bug. *** *** Bug 324470 has been marked as a duplicate of this bug. *** *** Bug 319932 has been marked as a duplicate of this bug. *** |
Build Identifier: 20100618-0524 Using the method ElementImpl.getAttribute(String) now returns empty string instead of null as previous version if an attribute is not found. But under some circumstances it throws a NPE. I'm trying to validate some files using an action that 'touches' all the xml files in a project, and then a builder performs the validation. The failure is in method getDefault(): return ((CMAttributeDeclaration) attribute).getAttrType().getImpliedValue(); The attribute is being found, but AttrType is null. The reason of this is unknown (I'm not very expert about xml...), but I noticed that the failure only happens when: 1) I'm validating a document that is also open in an editor (does not occur when validating xml not being in an editor) 2) It fails to find attributes undefined (NPE instead of "") when I look for attributes that are defined in other similar tags. My understanding is that the plugin is trying to deduce a default looking at other attributes whit the same name in the same doc. I see that I should have used hasAttribute instead (it works as expected) but I think there are lot of people extending the WTP using the return value of getAttribute to see if it is defined or not. Reproducible: Always Steps to Reproduce: 1. Load an XML in an editor where there are 2 tags with different attributes. 2. Try to call 'getAttribute' looking for an attribute defined in another tag For example <root> <a r="1"/> <a> </root> if you call getAttribute("r") on the second tag there getAttribute() throws a NPE if the document is loaded in an editor, returns "" if not loaded in an editor.