Exception while calling PsiElement.setName

Hello,

I wasn't sure if it's something I did wrong, or an EAP bug - so I decided to post here before
opening a JIRA issue. I have a plugin which uses PSI to chane an XmlTag's name (via setName). It
usually works very well, but on one occasion (could not reproduce since) I have run into the
following exception:

java.lang.NullPointerException
at com.intellij.psi.impl.source.tree.ChangeUtil.copyElement(ChangeUtil.java:232)
at com.intellij.psi.impl.source.xml.XmlTagImpl$2.runInner(XmlTagImpl.java:1)
at com.intellij.pom.impl.PomTransactionBase.run(PomTransactionBase.java:28)
at com.intellij.pom.core.impl.PomModelImpl.runTransaction(PomModelImpl.java:34)
at com.intellij.psi.impl.source.xml.XmlTagImpl.setName(XmlTagImpl.java:66)
at
org.mevenide.idea.psi.util.PsiUnnamedPropertyChangeListener$TagRenamerRunnable.run(PsiUnnamedPropertyChangeListener.java:342)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:122)
at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java)
at org.mevenide.idea.util.IDEUtils$1.run(IDEUtils.java:35)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:168)
at org.mevenide.idea.util.IDEUtils.runCommand(IDEUtils.java:33)
at
org.mevenide.idea.psi.util.PsiUnnamedPropertyChangeListener.renameProperty(PsiUnnamedPropertyChangeListener.java:98)
at
org.mevenide.idea.psi.support.AbstractPsiUnnamedPropertyObservable.renameProperty(AbstractPsiUnnamedPropertyObservable.java:51)
at
org.mevenide.idea.editor.pom.ui.dependencies.DependencyPropertiesTableModel.setValueAt(DependencyPropertiesTableModel.java:38)
at javax.swing.JTable.setValueAt(JTable.java:1875)
at javax.swing.JTable.editingStopped(JTable.java:3333)
at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:124)
at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:329)
at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:214)
at javax.swing.JTable$GenericEditor.stopCellEditing(JTable.java:3677)
at com.intellij.util.ui.Table.editCellAt(Table.java:110)
at javax.swing.plaf.basic.BasicTableUI$Handler.adjustFocusAndSelection(BasicTableUI.java:922)
at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(BasicTableUI.java:889)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:222)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:221)
at java.awt.Component.processMouseEvent(Component.java:5485)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3889)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:144)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:59)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:82)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

I was wondering if someone from JB could shed a light on why it happened. So far I haven't been able
to reproduce it, but ofcourse, I will post again once I figure out why it happened.

Thanks,
Arik Kfir.

13 comments
Comment actions Permalink

What build that's from? I get out of lines with 3386.
Anyway, that's most probably mean you're trying to call setName() against
invalid (xmlTag.isValid() == false) tag. Where that tag comes from?

-


Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink

Hi maxim!

the build is 3386 indeed, and the tag is fetched via standard PSI interfaces (e.g. using PsiManager
to acquire the XmlFile for my Document, then get the XmlTag from there).

However, it is possible the tag is no longer valid - I'll look into that. Now that you mention it -
I think it happened after multiple changes - in which case the first change might have caused the
rest of the tags to be invalidated.

I got the tag via XmlTag.getSubTags() - so if I changed the first tag, it might have affected the
rest of the tags in the array - is that a plausible scenario?

Maxim Shafirov (JetBrains) wrote:

What build that's from? I get out of lines with 3386.
Anyway, that's most probably mean you're trying to call setName()
against invalid (xmlTag.isValid() == false) tag. Where that tag comes from?

-------------------
Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

0
Comment actions Permalink

This exception caused by call for getName in tag without name token.
We'll fix this.

IK
Arik Kfir wrote:

Hello,

I wasn't sure if it's something I did wrong, or an EAP bug - so I
decided to post here before opening a JIRA issue. I have a plugin which
uses PSI to chane an XmlTag's name (via setName). It usually works very
well, but on one occasion (could not reproduce since) I have run into
the following exception:

java.lang.NullPointerException
at
com.intellij.psi.impl.source.tree.ChangeUtil.copyElement(ChangeUtil.java:232)

at
com.intellij.psi.impl.source.xml.XmlTagImpl$2.runInner(XmlTagImpl.java:1)
at
com.intellij.pom.impl.PomTransactionBase.run(PomTransactionBase.java:28)
at
com.intellij.pom.core.impl.PomModelImpl.runTransaction(PomModelImpl.java:34)

at
com.intellij.psi.impl.source.xml.XmlTagImpl.setName(XmlTagImpl.java:66)
at
org.mevenide.idea.psi.util.PsiUnnamedPropertyChangeListener$TagRenamerRunnable.run(PsiUnnamedPropertyChangeListener.java:342)

at
com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:122)

at
com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java)

at org.mevenide.idea.util.IDEUtils$1.run(IDEUtils.java:35)
at
com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:168)

at org.mevenide.idea.util.IDEUtils.runCommand(IDEUtils.java:33)
at
org.mevenide.idea.psi.util.PsiUnnamedPropertyChangeListener.renameProperty(PsiUnnamedPropertyChangeListener.java:98)

at
org.mevenide.idea.psi.support.AbstractPsiUnnamedPropertyObservable.renameProperty(AbstractPsiUnnamedPropertyObservable.java:51)

at
org.mevenide.idea.editor.pom.ui.dependencies.DependencyPropertiesTableModel.setValueAt(DependencyPropertiesTableModel.java:38)

at javax.swing.JTable.setValueAt(JTable.java:1875)
at javax.swing.JTable.editingStopped(JTable.java:3333)
at
javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:124)

at
javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:329)

at
javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:214)
at javax.swing.JTable$GenericEditor.stopCellEditing(JTable.java:3677)
at com.intellij.util.ui.Table.editCellAt(Table.java:110)
at
javax.swing.plaf.basic.BasicTableUI$Handler.adjustFocusAndSelection(BasicTableUI.java:922)

at
javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(BasicTableUI.java:889)

at
java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:222)
at
java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:221)
at java.awt.Component.processMouseEvent(Component.java:5485)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:3889)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at
com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:144)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:59)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:82)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)

at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)

at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

I was wondering if someone from JB could shed a light on why it
happened. So far I haven't been able to reproduce it, but ofcourse, I
will post again once I figure out why it happened.

Thanks,
Arik Kfir.

0
Comment actions Permalink

I was wrong. That one was because of invalid tag name (empty for example
or containing some illegal chars).

IK
Igor Kuralenok (JetBrains) wrote:

This exception caused by call for getName in tag without name token.
We'll fix this.

IK

0
Comment actions Permalink

Oh I see - so if the user enters an illegal tag name, getName() will always throw an exception? Is
this something a plugin needs to catch and handle, or will this be fixed in the PSI impl?

thank you so much for your help!


Igor Kuralenok (JetBrains) wrote:

I was wrong. That one was because of invalid tag name (empty for example
or containing some illegal chars).

IK
Igor Kuralenok (JetBrains) wrote:

>> This exception caused by call for getName in tag without name token.
>> We'll fix this.
>>
>> IK

0
Comment actions Permalink

Arik Kfir wrote:

Oh I see - so if the user enters an illegal tag name, getName() will
always throw an exception?

getName -- no, setName -- yes.

Is this something a plugin needs to catch and
handle, or will this be fixed in the PSI impl?

I can try to handle this but in this case I'll have to throw
IncorrectOperationException. I think it's reasonable to handle this
situation in plugin. Just check that name consists from valid chars.

IK

0
Comment actions Permalink

but how can I know if the name is valid if I can't call "getName()"? The XML is typed by the user,
not by the plugin - the plugin only inspects what the user entered...


Igor Kuralenok (JetBrains) wrote:

Arik Kfir wrote:

>> Oh I see - so if the user enters an illegal tag name, getName() will
>> always throw an exception?


getName -- no, setName -- yes.

>> Is this something a plugin needs to catch and handle, or will this be
>> fixed in the PSI impl?


I can try to handle this but in this case I'll have to throw
IncorrectOperationException. I think it's reasonable to handle this
situation in plugin. Just check that name consists from valid chars.

IK

0
Comment actions Permalink

Arik Kfir wrote:

but how can I know if the name is valid if I can't call "getName()"? The
XML is typed by the user, not by the plugin - the plugin only inspects
what the user entered...


Hmm... From your stacktrace I found that you call setName()... Am I wrong?

IK

0
Comment actions Permalink

oh I thought we were talking about the getName...my bad..

anyway - regarding setName - I think that if I pass illegal chars to it, an
IncorrectOperationException should be thrown, rather than an NPE (rather nasty catching an NPE in code)


Igor Kuralenok (JetBrains) wrote:

Arik Kfir wrote:

>> but how can I know if the name is valid if I can't call "getName()"?
>> The XML is typed by the user, not by the plugin - the plugin only
>> inspects what the user entered...


Hmm... From your stacktrace I found that you call setName()... Am I wrong?

IK

0
Comment actions Permalink

Arik Kfir wrote:

oh I thought we were talking about the getName...my bad..

anyway - regarding setName - I think that if I pass illegal chars to it,
an IncorrectOperationException should be thrown, rather than an NPE
(rather nasty catching an NPE in code)

:). Sure. But I'm not sure if I manage to fix this before release (lot
of work in completion, jsp and other stuff).

IK

0
Comment actions Permalink

is ok - would you like me to open a JIRA on this?


Igor Kuralenok (JetBrains) wrote:

Arik Kfir wrote:

>> oh I thought we were talking about the getName...my bad..
>>
>> anyway - regarding setName - I think that if I pass illegal chars to
>> it, an IncorrectOperationException should be thrown, rather than an
>> NPE (rather nasty catching an NPE in code)


:). Sure. But I'm not sure if I manage to fix this before release (lot
of work in completion, jsp and other stuff).

IK

0
Comment actions Permalink

Arik Kfir wrote:

is ok - would you like me to open a JIRA on this?

Ok. Thanks.

IK

0
Comment actions Permalink

A little late, but here it is: http://www.jetbrains.net/jira/browse/IDEA-3460

Igor Kuralenok (JetBrains) wrote:

Arik Kfir wrote:

>> is ok - would you like me to open a JIRA on this?


Ok. Thanks.

IK

0

Please sign in to leave a comment.