java.lang.ClassFormatError: Invalid method Code length while using PowerMock - junit

I am running JUnit case with PowerMock in jdk7 using the below libraries :
cglib-nodep-2.2.2.jar
javassist-3.19.0-GA.jar
junit-4.12.jar
mockito-all-1.10.19.jar
objenesis-2.1.jar
powermock-mockito-1.6.2-full.jar
Below is code snippet from my Unit Test in which I am using PowerMock
#RunWith(PowerMockRunner.class)
#PrepareForTest(ValidateBindingImpl.class)
public class ValidateBindingImplTest{
//more code follows
}
While executing this test case I am getting following error:
java.lang.ClassFormatError: Invalid method Code length 119842 in class file com/v1/ValidateBindingImpl
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:269)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:180)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:68)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:95)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:370)
at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:351)
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:653)
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:460)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:286)
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:222)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3079)
at java.lang.Class.getAnnotation(Class.java:3038)
at org.junit.internal.MethodSorter.getDeclaredMethods(MethodSorter.java:52)
at org.junit.internal.runners.TestClass.getAnnotatedMethods(TestClass.java:45)
at org.junit.internal.runners.MethodValidator.validateTestMethods(MethodValidator.java:71)
at org.junit.internal.runners.MethodValidator.validateStaticMethods(MethodValidator.java:44)
at org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:50)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.validate(PowerMockJUnit44RunnerDelegateImpl.java:108)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.<init>(PowerMockJUnit44RunnerDelegateImpl.java:70)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl.<init>(PowerMockJUnit47RunnerDelegateImpl.java:42)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit49RunnerDelegateImpl.<init>(PowerMockJUnit49RunnerDelegateImpl.java:25)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:156)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:40)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:244)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:61)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Found similar post discussed here and here based on which I tried adding -XX:-UseSplitVerifier in VM arguments but it didn't work.
Moreover I understand that the error seem to occur due to lengthy method in my class file but as its my organization code I wont be able modify/split the method as suggested in some posts online.

You faced with the following issue: JVM has limit on method size in bites, but during byte code transformation which is required to make possible mocking static, final size of the method could exceed this limit. In this case you see this error
java.lang.ClassFormatError: Invalid method Code length 119842 in class file
In next release will be include fix, which addressed this issue by replacing huge method via code which throws exception by default, but you still able to suppress such, method.
But, it's still will be only workaround for classes you cannot modified. Right way to fix the issue, it's to refactor your code to make method smaller. There are a lot of refactoring techniques to achieve this goal.

You will probably not like my answer, but the only reasonable answer is: stop using PowerMock.
If your production code is such that you need PowerMock in order write unit tests; then seriously: change your production code. If you need PowerMock, then your "code under test" is most likely: bad.
PowerMock (and all other mocking frameworks that rely on byte code manipulation) most often, cause more trouble than good. They cause issues like the one you got now; they very much limit your ability to use different JVMs or to run coverage tools.
This comes from a person who spent countless hours fixing "PowerMock" based unit tests; and who has written hundreds of unit tests over the last months only relying on EasyMock; and not once had the need to turn to PowerMock.

To use JVM option '-noverify': https://bugs.eclipse.org/bugs/show_bug.cgi?id=435446

As mentioned earlier, this can happen not just by trying to instrument a large method, but also trying to instrument a class with a large number of methods.
I've encountered a break at around +/- 1500 methods. It depends on the methods signatures in the class.
Try to reduce the number of methods in the class.

Related

bootstrap PowerMock with #Rule ,but failed

#RunWith(PowerMockRunner.class)
#PrepareForTest({ SessionUtil.class})
public class FundControllerTest {
XXXXXXXXXXXXXXX.......
}
Run Junit as above, it works well.
But when I try to run Junit as below, it failed. Because I need use Eclemma to
coverage my test, so I switch to use #Rule to bootstrap PowerMock, but failed. Please help.
#PrepareForTest({ SessionUtil.class})
public class FundControllerTest {
#Rule
public PowerMockRule rule = new PowerMockRule();
/*
static{
PowerMockAgent.initializeIfNeeded();
}
*/
XXXXXXXXXXXXXXXXXXXXXXXXX..........
}
java.lang.RuntimeException: com.sun.tools.attach.AttachNotSupportedException: Unable to enqueue operation: the target VM does not support attach mechanism
at org.powermock.modules.agent.AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(AgentLoader.java:122)
at org.powermock.modules.agent.AgentLoader.loadAgent(AgentLoader.java:81)
at org.powermock.modules.agent.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:40)
at org.powermock.modules.agent.PowerMockAgent.initializeIfNeeded(PowerMockAgent.java:91)
at com.hsbc.mf.frtend.twfunds.controller.FundControllerTest.<clinit>(FundControllerTest.java:53)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:199)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:56)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:39)
at java.lang.reflect.Constructor.newInstance(Constructor.java:527)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to enqueue operation: the target VM does not support attach mechanism
at sun.tools.attach.WindowsVirtualMachine.<init>(WindowsVirtualMachine.java:64)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:56)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:39)
at java.lang.reflect.Constructor.newInstance(Constructor.java:527)
at org.powermock.reflect.internal.WhiteboxImpl.createInstance(WhiteboxImpl.java:1455)
at org.powermock.reflect.internal.WhiteboxImpl.invokeConstructor(WhiteboxImpl.java:1303)
at org.powermock.reflect.Whitebox.invokeConstructor(Whitebox.java:497)
at org.powermock.modules.agent.AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(AgentLoader.java:120)
... 28 more
When you find a snake in your bed, does it matter whether it crawled through the open window; or came through the front door?
In other words: in order to allow for mocking static code; PowerMock needs to manipulate the byte code of that production class SessionUtils. And EclEmma also relies on byte code manipulation.
Perhaps, at some future point, the implementations of both frameworks will work together (but the corresponding bug is almost two years old; and there isn't much activity around it; so don't hold your breath on it).
But today, PowerMock and EclEmma do not work together. End of story.
And it doesn't matter to "pull in" PowerMock using its own runner; or using the "rule approach". Because as said: the problem is that you found that snake in your bed; and not "how did it get there".
Now you simply have to decide what is more important to you: to keep your production code as is (and its design, that forces you to mock static calls with PowerMock); or to acquire coverage information.
My personal two cents: that is one of the reasons why my team gave up on PowerMock completely. Instead, we focus on writing code that is testable without mocking static/new calls; and guess what: that works fine. And our production code is better than before.

Liferay upload file bug

Is there any quick fix for liferay, to fix upload file bug.During upload I have :
ERROR [BufferedIncreament-DLFolderLocalService.updateLastPostDate(long,Date)-1][BufferedIncrementRunnable:68] Unable to write buffered increment value to the database
java.lang.NullPointerException
at java.util.Date.getMillisOf(Date.java:956)
at java.util.Date.before(Date.java:915)
at com.liferay.portlet.documentlibrary.service.impl.DLFolderLocalServiceImpl.updateLastPostDate(DLFolderLocalServiceImpl.java:1095)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
at com.liferay.portal.increment.BufferedIncreasableEntry.proceed(BufferedIncreasableEntry.java:48)
at com.liferay.portal.increment.BufferedIncrementRunnable.run(BufferedIncrementRunnable.java:65)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
The only solution I know is reset of DB schema - which could be problematic :( Help!
You should report the issue at issues.liferay.com (unless you find that one already exists) and do either of:
Wait until it is fixed.
Create an ext plugin and add a check to DLFolderLocalServiceImpl.updateLastPostDate:
if (dlFolder.getLastPostDate() != null
&& lastPostDate.before(dlFolder.getLastPostDate())) {
return;
}
Don't use document folders (just put everything into the root)
Temporarily fix this for all existing folders by updating the lastPostDate for all document folders in the database while your server is offline (or flush the cache afterwards):
UPDATE DLFOLDER SET LASTPOSTDATE = NOW() WHERE LASTPOSTDATE IS NULL
Liferay runs quite a bit of code to make sure that service builder has its context - if your stacktrace isn't shortened, it looks like you're running in a request-independent thread, which might not have servicebuilder initialized correctly (obviously).
Thus it might be that it isn't a bug in Liferay, but you'd need to prepare the environment the same way that Liferay prepares it. I can't exactly point you to the necessary steps, but you might keep that in mind. Also, nothing in the stacktrace points to an "upload bug" IMHO, as you're only touching the last post date
If you omitted parts of the stacktrace, it'd be good to signal that with "..." where you leave out stuff. It doesn't look complete to me. The parts you posted don't really look proper to me.

Physics Body Editor error

I get this error when trying to initialize BodyEditorLoader from this library http://www.aurelienribon.com/blog/projects/physics-body-editor/
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:127)
Caused by: java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J
at com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape(Native Method)
at com.badlogic.gdx.physics.box2d.PolygonShape.<init>(PolygonShape.java:29)
at aurelienribon.bodyeditor.BodyEditorLoader.<init>(BodyEditorLoader.java:31)
How can i fix it?
to see the code where it is called, but I venture to say that the problem is the call to your world this must be called before here's an example:
This a example compile good:
oWorld = new World(gravedad, dormir);
loader = new BodyEditorLoaderNewW(
Gdx.files.internal("data/test.json"));
This a example not compile good:
loader = new BodyEditorLoaderNewW(
Gdx.files.internal("data/test.json"));
oWorld = new World(gravedad, dormir);
recive this:
java.lang.UnsatisfiedLinkError:
com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape () J
note the difference in the world is called one after so gives:
it is possible that in the future can, need this:
BodyEditorLoader - noSuchMethod
but if this is not the solution you could put some of the code, I hope you help
Based on this https://github.com/libgdx/libgdx/issues/2393 the problem is because natives aren't loaded before creating shape.
There are two solutions:
First is creating World instance before creating any shapes.
Second is calling Box2D.init(); before creating any shapes. This method is preferred because you don't need to create World instance and it's much more obvious.
Use this version https://gist.github.com/grulg/8691e7ee7709367ce165 instead of version from Google Code.

GWT-Tutorial StockWatcher, not using new HTML-File

I am currently working through the StockWatcher-Tutorial on the GWT page and come this far to Step 3: Build the User Interface.
I changed the content of the hosted HTML-page as said and done the rest of the tutorial.
But when I try to test the new page and start Run > Debug As > Web Application, I get an exception in onLoad():
onModuleLoad() threw an exception Exception while loading module
com.ma.project.client.MaWebAppProject. See Development Mode for
details.
java.lang.reflect.InvocationTargetException 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
com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396) at
com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at
com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at
com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source) Caused by:
java.lang.NullPointerException at
com.ma.project.client.MaWebAppProject.onModuleLoad(MaWebAppProject.java:41)
... 9 more
and the Development Mode Tab in Eclipse says:
[ERROR] [mawebappproject] - Unable to load module entry point class
com.ma.project.client.MaWebAppProject (see associated exception for
details)
I have found out so far, it seems the changes I made in the HTML-file are not recognized by the development server although I saved the file and everything. I tried to use the GWT Compile Project but no effect.
Seems the Java Code is crashing because it can not find the , which is used as the RootPanel.
Does anyone have an idea?
UPDATE: After some trail and error I found out I had to refresh the page once in the browser after the error message. The it worked. I still don't know why this happened, but so far it not happened again...
could it be that you have replaced the whole html file with the one from the page. this can cause a problem, because on the page, it uses your project name which is certainly not stockwatcher but apparently something like this: com.ma.project.client.MaWebAppProject (guessed).
I suggest you only you restore the last running state and replace only the lines which are marked yellow, then it should work.
The other reason could be that you didn't use RootPanel.get("stockList") or gave another name to the id div (this one: <div id="stockList"></div>). These two names must be identical (and the id field unique of course), because the RootPanel get method searches for a field with that id and places the Widget inside of it. (btw: RootPanel.get() with no parameters, it uses the body element so you can also try this).
Well this are all possibilities right now^^
I think I had this exact issue. My problem ended up being that the word "stocklist" was lower case in the html id like so:
<div id="stocklist"></div>
but was camel cased in the java code where the stocklist is associated with the main panel:
RootPanel.get("stockList").add(mainPanel);
The solution was, of course, to make one match the other.

How does JUnit find the eclipse plug-in being tested?

I am writing a plug-in (ClassRefactoringPlugin) that examines source code in Eclipse 3.6.1. The plug-in contains a CallData class that examines a Java source file and figures out which Java elements are called from a method using JDT operations. I wrote a JUnit 4 test for this class that also resides in the ClassRefactoringPlugin project. When I ran it as a JUnit plug-in test, I got:
Java Model Exception: Java Model Status [ClassRefactoringPlugin does not exist]
What have I done wrong? The configuration specifies to launch with all workspace and enabled target plug-ins, and ClassRefactoringPlugin is in my dropins directory. (Although shouldn't the project's version of the plug-in be recognized by the spawned workspace?)
Here's the stack trace:
!MESSAGE CallData.calculateCalledMethods: Java Model Exception: Java Model Status [ClassRefactoringPlugin does not exist]
Java Model Exception: Java Model Status [ClassRefactoringPlugin does not exist]
at org.eclipse.jdt.internal.core.JavaElement.newJavaModelException(JavaElement.java:502)
at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:246)
at org.eclipse.jdt.internal.core.Openable.openAncestors(Openable.java:504)
at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:240)
at org.eclipse.jdt.internal.core.Openable.openAncestors(Openable.java:504)
at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:240)
at org.eclipse.jdt.internal.core.Openable.openAncestors(Openable.java:504)
at org.eclipse.jdt.internal.core.CompilationUnit.openAncestors(CompilationUnit.java:1170)
at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:240)
at org.eclipse.jdt.internal.core.SourceRefElement.generateInfos(SourceRefElement.java:107)
at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:515)
at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:252)
at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:238)
at org.eclipse.jdt.internal.core.JavaElement.getChildren(JavaElement.java:193)
at org.eclipse.jdt.internal.core.JavaElement.getChildrenOfType(JavaElement.java:207)
at org.eclipse.jdt.internal.core.SourceType.getMethods(SourceType.java:403)
at nz.ac.vuw.ecs.kcassell.utils.EclipseSearchUtils.addDesiredMethods(EclipseSearchUtils.java:333)
at nz.ac.vuw.ecs.kcassell.utils.EclipseSearchUtils.getMethods(EclipseSearchUtils.java:210)
at nz.ac.vuw.ecs.kcassell.callgraph.CallData.collectMethodCallData(CallData.java:203)
at nz.ac.vuw.ecs.kcassell.callgraph.CallData.calculateCalledMethods(CallData.java:176)
at nz.ac.vuw.ecs.kcassell.callgraph.CallData.collectCallData(CallData.java:151)
at nz.ac.vuw.ecs.kcassell.callgraph.CallDataTest.testCollectCallData(CallDataTest.java:67)
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 junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
at org.eclipse.pde.internal.junit.runtime.UITestApplication$1.run(UITestApplication.java:116)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3515)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3164)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
at org.eclipse.pde.internal.junit.runtime.UITestApplication.start(UITestApplication.java:47)
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)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
I am wondering if the error message might be a red herring. The error occurs when making a call to
IMethod[] methods = type.getMethods();
If I set a breakpoint there and look at type in the Variables view of the debugger, I see:
CallDataTest (not open) [in CallDataTest.java [in nz.ac.vuw.ecs.kcassell.callgraph [in test [in ClassRefactoringPlugin]]]]
I wonder if I am omitting some important preliminary step to make the project available for examination. First, I attempt to activate the workbench, like so:
public static void activateWorkbench() {
// possible for PlatformUI.getWorkbench to throw an IllegalStateException
// if the workbench is not yet started e.g createAndRunWorkbench() has not yet been called
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow =
workbench.getActiveWorkbenchWindow();
workbenchWindow.getActivePage();
}
Then I try to get type using its handle:
protected IType iType = EclipseUtils.getTypeFromHandle(
"=ClassRefactoringPlugin/test<nz.ac.vuw.ecs.kcassell.callgraph{CallDataTest.java[CallDataTest");
public static IType getTypeFromHandle(String handle) {
IType type = null;
IJavaElement element = JavaCore.create(handle);
if (element == null) {
System.err.println(" No element created from " + handle);
} else if (element instanceof IType) {
type = (IType) element;
}
return type;
}
I am new to plug-in development, so any help would be much appreciated.
Cheers,
Keith
I am a little unsure exactly what you are trying to do here, but it looks like you are trying to write a JUnit test for your plugin. Is this right?
According to the java element handle identifier that you are creating, there should be a project called ClassRefactoringPlugin in your workspace and in there, is a source folder called test, and a java class called CallDataTest in a package called nz.ac.vuw.ecs.kcassell.callgraph.
I'm guessing that this is not the case and that you want to reference a class file in the plugin that you just created.
Before you can do any of that, you need to import a project into your test workspace, set its classpath, and then you can access its contents using handle identifiers.
I may be misunderstanding what you are trying to do, but it does seem like you are trying to access a java file that doesn't exist in your workspace. If you can confirm that this is what you want to do, I can point you to some test code that does exactly what you want.
There are some open source projects that do exactly this and you can borrow some of their source code for your purpose. A project that I am familiar with is Groovy-Eclipse http://groovy.codehaus.org/Eclipse+Plugin (since I am the lead on that project).
Here is a link to the class that we use to create and manage test projects:
https://svn.codehaus.org/groovy/eclipse/trunk/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/TestProject.java
You can use some or all of this code for your own tests. Just remember to delete all projects at the end of each test.
Had a similar error for different reasons. My error started after renaming the target package in the project. After I tried the solution from paskster without success, I started diggin'.
The actual problem was that renaming the package name from the manifest file didn't work as expected. I thought it would change everything everywhere. However, the old package name was still in the manifest file in the test directory, and in some views in the resources. After renaming those manually and rebuilding the project, the error was gone.
This is the accepted answer for another question:
Java Model Exception: Java Model Status [gen [in MyApp] does not exist] after Eclipse Android project Clean
Since the owner of this question up-voted this answer as a solution with a link to this question, I thought I'd post it here as well.