Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerMock Agent and TestNG 6.9.+ #1001

Closed
thekingn0thing opened this issue Mar 14, 2016 · 6 comments
Closed

PowerMock Agent and TestNG 6.9.+ #1001

thekingn0thing opened this issue Mar 14, 2016 · 6 comments

Comments

@thekingn0thing
Copy link

I'm working on following issue powermock/powermock#640

Everything fine in case if PowerMock and TestNG are sued without attaching javaagent, but in case if a user wants use PowerMock Java Agent instead PowerMockObjectFactory then the following exception is thrown

objc[56954]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
java.lang.VerifyError: Expecting a stackmap frame at branch target 11
Exception Details:
Location:
org/testng/internal/ObjectFactoryImpl.newInstance(Ljava/lang/reflect/Constructor;[Ljava/lang/Object;)Ljava/lang/Object; @0: aload_1
Reason:
Expected stackmap frame at this location.
Bytecode:
0x0000000: 2b04 b600 1f2b 2cb6 0022 b04e 2bb6 0026
0x0000010: b800 2cb0 4e2b b600 26b8 002c b04e bb00
0x0000020: 2e59 bb00 3059 b700 3112 33b6 0037 2bc6
0x0000030: 000d 2bb6 0026 b600 3da7 0005 123f b600
0x0000040: 37b6 0042 2db7 0045 bf

Exception Handler Table:
bci [0, 10] => handler: 11
bci [0, 10] => handler: 20
bci [0, 10] => handler: 29

at org.powermock.modules.testng.PowerMockObjectFactory.(PowerMockObjectFactory.java:37)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at org.testng.xml.TestNGContentHandler.xmlSuite(TestNGContentHandler.java:205)
at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:519)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:745)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:380)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:614)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3135)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:118)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
at org.testng.xml.XMLParser.parse(XMLParser.java:39)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:16)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:9)
at org.testng.xml.Parser.parse(Parser.java:172)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:305)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:44)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

And it's issue only with TestNG 6.9+. I cannot figure out what changed in TestNG since 6.8.22. I see it Git history that the ObjectFactoryImpl has not been changed since 6.8.22 release.

By the way, PowerMock javaagent in this case doesn't modified the ObjectFactoryImpl class.

I create the sample which can help to reproduce the issue
https://github.com/thekingnothing/testng-sample

Could you help me?

@juherr
Copy link
Member

juherr commented Mar 14, 2016

Strange behavior and I'm not familiar with agent or bytecode.

But I found some links:
http://stackoverflow.com/questions/7936006/why-am-i-getting-the-following-error-when-running-google-app-from-eclipse
http://stackoverflow.com/questions/15122890/java-lang-verifyerror-expecting-a-stackmap-frame-at-branch-target-jdk-1-7
luontola/retrolambda#25

As I understand them, it could work out-of-the-box with java7 specific options.

The next question will be: where exactly and why is stackmap missing? Is there some generated code somewhere?

@thekingn0thing
Copy link
Author

I've also found that -noverify option could help (I haven't tested it yet), but I wonder what was changed that could break using Java Agent. As I mentioned, there is no class chasing in this case the PowerMockClassTransformer returns null as it's recommended in [documentation](http://docs.oracle.com/javase/8/docs/api/java/lang/instrument/ClassFileTransformer.html#transform-java.lang.ClassLoader-java.lang.String-java.lang.Class-java.security.ProtectionDomain-byte:A- and it means that class isn't transformed.

Has been changed version of JDK which is used to build TestNG? Or any other environment changing since 6.8.22 ?

@juherr
Copy link
Member

juherr commented Mar 14, 2016

Has been changed version of JDK which is used to build TestNG? Or any other environment changing since 6.8.22 ?
I don't know what JDK @cbeust used for the releases, but we can imagine he sometimes upgraded its environment.

TestNG 6.9.4 dropped Java6 support: https://github.com/cbeust/testng/blob/master/CHANGES.txt#L83
Don't know if it change something or not.

And I still don't understand why it is working well without agent.

@thekingn0thing
Copy link
Author

Finally, I've figured out what happen. It's there complex issue and several little mistakes and issue evolve into such stranger defect.

  • Since,TestNG 6.9.4 the 1.7 is target byte code version.
  • In JDK 1.7 Stack Map Frames verifying became mandatory.
  • I've found deeper in javagnet that even if class does not modified, it is gone through ASM ne way or another to remove final modifier. (And I fixed issue here)
  • ASM had a defect regarding incorrect byte code generation for JDK 7 and higher
  • javaagent cannot use dependencies, so ASM was repacked into PowerMock JavaAgent. (I've been trying repacked several ASM version, but I've failed, maybe some other classes which use ASM also should be changed, I will do it later)

Result: incorrect byte generation -> java.lang.VerifyError: Expecting a stackmap frame at branch target 11

Why it's working well without agent? Because, without agent we can what we want with class and we use Javassist to remove final modifier and it correctly use latest ASM version without this defect. I guess, or Javassist somehow handle this case.

Thank you! I'm closing the issue.

@juherr
Copy link
Member

juherr commented Mar 16, 2016

👍 Thank for the explaination!

And happy to know it will be fixed :)

@cbeust
Copy link
Collaborator

cbeust commented Mar 16, 2016

Indeed, thanks for the detective work, @thekingnothing, very impressive!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants