weird PSI problem with interfaces...

I've got this weird PSI problem, my code is happily added/updating Javadoc
via PSI for class methods, but the moment the code is triggered when
editing the method declaration ( anything thats not under the PsiCodeBlock
I get a NullPointereException inside the PSI code with the following
stacetrace:

java.lang.NullPointerException
at com.intellij.psi.impl.source.e.e.c(e.java:25)
at com.intellij.psi.impl.source.b.r.a(r.java:109)
at com.intellij.psi.impl.source.b.s.replace(s.java:77)
at com.talios.jira.idea.JiraAnnotationListener$3.run(JiraAnnotationListener.java:115)
at com.intellij.openapi.application.a.b.runWriteAction(b.java:161)
at com.talios.jira.idea.JiraAnnotationListener$2.run(JiraAnnotationListener.java:96)
at com.intellij.openapi.command.impl.a.executeCommand(a.java:107)
at com.talios.jira.idea.JiraAnnotationListener$1.run(JiraAnnotationListener.java:94)
at com.intellij.openapi.application.LaterInvocator$FlushQueue.run(LaterInvocator.java:19)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at com.intellij.ide.q.b(q.java:118)
at com.intellij.ide.q.a(q.java:10)
at com.intellij.ide.q.dispatchEvent(q.java:131)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)



This is triggered by:
PsiDocumentManager pdm = PsiDocumentManager.getInstance(project);
pdm.commitDocument(documentEvent.getDocument());
final PsiElement comment = ((PsiMethod) method).getDocComment();

PsiComment newElement = getJavaDocForIssue(
jiraConfigurationComponent.getItemWorkedOn());
added = method.addBefore(newElement, comment);


newElement isn't null, method isn't null, and comment isn't null in this
code path.

This works fine when editing code bodies, but regularly fails when editing
the declation/parameter list/throws list etc. etc.

Is this a bug inside PSI?

5 comments

On 2/7/04 2:43 AM, in article pan.2004.02.06.23.42.32.753335@talios.com,
"Mark Derricutt" <mark@talios.com> wrote:

java.lang.NullPointerException
at com.intellij.psi.impl.source.e.e.c(e.java:25)
at com.intellij.psi.impl.source.b.r.a(r.java:109)
at com.intellij.psi.impl.source.b.s.replace(s.java:77)
at
com.talios.jira.idea.JiraAnnotationListener$3.run(JiraAnnotationListener.java:
115)
at com.intellij.openapi.application.a.b.runWriteAction(b.java:161)
at
com.talios.jira.idea.JiraAnnotationListener$2.run(JiraAnnotationListener.java:
96)
at com.intellij.openapi.command.impl.a.executeCommand(a.java:107)
at
com.talios.jira.idea.JiraAnnotationListener$1.run(JiraAnnotationListener.java:
94)
at
com.intellij.openapi.application.LaterInvocator$FlushQueue.run(LaterInvocator.
java:19)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at com.intellij.ide.q.b(q.java:118)
at com.intellij.ide.q.a(q.java:10)
at com.intellij.ide.q.dispatchEvent(q.java:131)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java
:201)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:1
51)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)


What build is it? So I can unscramble the stacktrace...

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


0

On Sat, 07 Feb 2004 14:16:59 +0300, Maxim Shafirov (JetBrains) wrote:

What build is it? So I can unscramble the stacktrace...


That trace was from 1144.

0

Mark Derricutt wrote:

I've got this weird PSI problem, my code is happily added/updating Javadoc
via PSI for class methods, but the moment the code is triggered when
editing the method declaration ( anything thats not under the PsiCodeBlock
I get a NullPointereException inside the PSI code with the following
stacetrace:

java.lang.NullPointerException
at com.intellij.psi.impl.source.e.e.c(e.java:25)
at com.intellij.psi.impl.source.b.r.a(r.java:109)
at com.intellij.psi.impl.source.b.s.replace(s.java:77)
at

>
com.talios.jira.idea.JiraAnnotationListener$3.run(JiraAnnotationListener.java:115)

at com.intellij.openapi.application.a.b.runWriteAction(b.java:161) at

>
com.talios.jira.idea.JiraAnnotationListener$2.run(JiraAnnotationListener.java:96)

at com.intellij.openapi.command.impl.a.executeCommand(a.java:107) at

>
com.talios.jira.idea.JiraAnnotationListener$1.run(JiraAnnotationListener.java:94)

at

>
com.intellij.openapi.application.LaterInvocator$FlushQueue.run(LaterInvocator.java:19)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178) at
java.awt.EventQueue.dispatchEvent(EventQueue.java:454) at
com.intellij.ide.q.b(q.java:118) at com.intellij.ide.q.a(q.java:10) at
com.intellij.ide.q.dispatchEvent(q.java:131) at

>
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at

>
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)



This is triggered by:
PsiDocumentManager pdm = PsiDocumentManager.getInstance(project);
pdm.commitDocument(documentEvent.getDocument());
final PsiElement comment = ((PsiMethod) method).getDocComment();

PsiComment newElement = getJavaDocForIssue(
jiraConfigurationComponent.getItemWorkedOn());
added = method.addBefore(newElement, comment);


newElement isn't null, method isn't null, and comment isn't null in this
code path.

This works fine when editing code bodies, but regularly fails when editing
the declation/parameter list/throws list etc. etc.


Quite so. PsiElements have a wonderful 'isValid()' method. What happens when
you commit document is that PSI reparses itself, hereby invalidating some
of its elements. When you edit a code block, PSI is smart enough not to
reparse a surrounding method; when you edit throws clause or parameter
list, it have to do so.

At 'pdm.commitDocument(...)' you have invalidated your 'method'. Hence the
stack trace.

Is this a bug inside PSI?


The only bug (in this case) is not overly-informative failure, perhaps.

Friendly,
Dmitry
--
Dmitry Lomov
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0

On Mon, 09 Feb 2004 13:13:52 +0300, Dmitry Lomov (JetBrains) wrote:

Quite so. PsiElements have a wonderful 'isValid()' method. What happens
when you commit document is that PSI reparses itself, hereby invalidating
some of its elements. When you edit a code block, PSI is smart enough not


Sounds logical when you explain whats happening...

At 'pdm.commitDocument(...)' you have invalidated your 'method'. Hence
the stack trace.


Hmmm, unforuntaly if I don't commit the document I get lots of size
mismatch errors. But now I know the reason, I can check the isValid() and
insert the PsiComment elsewhere in the Psi tree that works.

Mark

0

Mark Derricutt wrote:

On Mon, 09 Feb 2004 13:13:52 +0300, Dmitry Lomov (JetBrains) wrote:

>> Quite so. PsiElements have a wonderful 'isValid()' method. What happens
>> when you commit document is that PSI reparses itself, hereby invalidating
>> some of its elements. When you edit a code block, PSI is smart enough not


Sounds logical when you explain whats happening...

>> At 'pdm.commitDocument(...)' you have invalidated your 'method'. Hence
>> the stack trace.


Hmmm, unforuntaly if I don't commit the document I get lots of size
mismatch errors. But now I know the reason, I can check the isValid() and
insert the PsiComment elsewhere in the Psi tree that works.


I advise to commit your documents as early as possible, and work on PSI
level afterwards.

Friendly,
Dmitry

--
Dmitry Lomov
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0

Please sign in to leave a comment.