Oh dear, my plugin causes exceptions in IDEA 8!

http://www.jetbrains.net/jira/browse/IDEA-20755

I tried to make the plugin compatible to both IDEA 7 and 8 but something
must have gone terribly wrong!

When my plugin is installed in IDEA 8 the java source part of the
project view tree does not work anymore and keeps displaying
"Loading..." while idea.log shows an error:

2008-11-19 19:12:27,656 ERROR -
l.treeView.AbstractTreeUpdater -
com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane$5
java.lang.IllegalStateException: @NotNull method
com/intellij/psi/impl/PsiElementFactoryImpl.createRawSubstitutor must
not return null

See bug report for full stacktrace...

I used the following code to circumvent the incompatibility:

private static final Method getInstanceMethod;
private static final Method findClassMethod;

static
{
Class<?> clazz=null;
try
{
clazz = Class.forName("com.intellij.psi.JavaPsiFacade");
}
catch (ClassNotFoundException e)
{
try
{
clazz = Class.forName("com.intellij.psi.PsiManager");
}
catch (ClassNotFoundException e1)
{
e1.printStackTrace();
}
}
Method instanceMethod = null;
Method classMethod = null;
if(clazz!=null)
{
try
{
instanceMethod = clazz.getMethod("getInstance", Project.class);
classMethod = clazz.getMethod("findClass", String.class,
GlobalSearchScope.class);
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
}
getInstanceMethod = instanceMethod;
findClassMethod = classMethod;

}

private PsiClass findClass(Project project, String className,
GlobalSearchScope scope)
{
try
{
Object instance = getInstanceMethod.invoke(null, project);
if(instance != null)
{
return (PsiClass) findClassMethod.invoke(instance, className, scope);
}
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}
// IDEA 7: PsiManager.getInstance(project).findClass(className, scope);
// IDEA 8: JavaPsiFacade.getInstance(project).findClass(className,
scope);
System.err.println("Couldn't find class '"className"'!");
return null;
}
}

Does anyone have any idea what's wrong? Any help is really appreciated!

Joern.

1 comment
Comment actions Permalink

Ok, I fixed the problem.

I had to initialize the method variables in initComponent instead of
statically during class loading.

Now everything works as expected.

The change-notes are also schowing up. the problem is that only one
change is accepted in the "Update plugin" form each time so I had to
upload the new jar first, entered the form again, changed the next value
and so on...

Hope this helps someone...

Joern.

Joern Huxhorn wrote:

http://www.jetbrains.net/jira/browse/IDEA-20755

I tried to make the plugin compatible to both IDEA 7 and 8 but something
must have gone terribly wrong!

When my plugin is installed in IDEA 8 the java source part of the
project view tree does not work anymore and keeps displaying
"Loading..." while idea.log shows an error:

2008-11-19 19:12:27,656 ERROR -
l.treeView.AbstractTreeUpdater -
com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane$5
java.lang.IllegalStateException: @NotNull method
com/intellij/psi/impl/PsiElementFactoryImpl.createRawSubstitutor must
not return null

See bug report for full stacktrace...

I used the following code to circumvent the incompatibility:

private static final Method getInstanceMethod;
private static final Method findClassMethod;

static
{
Class<?> clazz=null;
try
{
clazz = Class.forName("com.intellij.psi.JavaPsiFacade");
}
catch (ClassNotFoundException e)
{
try
{
clazz = Class.forName("com.intellij.psi.PsiManager");
}
catch (ClassNotFoundException e1)
{
e1.printStackTrace();
}
}
Method instanceMethod = null;
Method classMethod = null;
if(clazz!=null)
{
try
{
instanceMethod = clazz.getMethod("getInstance", Project.class);
classMethod = clazz.getMethod("findClass", String.class,
GlobalSearchScope.class);
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
}
getInstanceMethod = instanceMethod;
findClassMethod = classMethod;

}

private PsiClass findClass(Project project, String className,
GlobalSearchScope scope)
{
try
{
Object instance = getInstanceMethod.invoke(null, project);
if(instance != null)
{
return (PsiClass) findClassMethod.invoke(instance, className, scope);
}
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}
// IDEA 7: PsiManager.getInstance(project).findClass(className, scope);
// IDEA 8: JavaPsiFacade.getInstance(project).findClass(className,
scope);
System.err.println("Couldn't find class '"className"'!");
return null;
}
}

Does anyone have any idea what's wrong? Any help is really appreciated!

Joern.

0

Please sign in to leave a comment.