vijayjcp / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 2 forks source link

MockClassLoader#loadMockClass fails to preserve original ProtectionDomain of classes prepared for test #544

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Try to use another bytecode manipulation tool together with PowerMock, for 
example, JaCoCo.

What is the expected output? What do you see instead?

The other tool should still be able to properly instrument classes that got 
prepared for test by PowerMock. Doing so might require that the original 
ProtectionDomain of the prepared class be preserved in the copy generated by 
MockClassLoader. JaCoCo, in particular, checks that the ProtectionDomain of 
each class has a code source location, to determine whether it's a legitimate 
".class" file from the codebase, or a dynamically generated class which only 
exists at runtime (and therefore should not be instrumented for coverage).

This can affect other tools, such as JMockit Coverage.

What version of the product are you using? On what operating system?

PowerMock 1.6.1, on Windows 7 (the OS or JDK version should not matter here).

Please provide any additional information below.

There is already a JaCoCo issue open: 
https://github.com/jacoco/jacoco/issues/294

I believe the fix should be relatively simple: PowerMock will need to save 
somewhere the ProtectionDomain of each class prepared for test (say, in a 
Map<String, ProtectionDomain>) of prepared class names), so that it can recover 
the PD and pass it in the call to "ClassLoader#defineClass" at the end of 
"loadMockClass". This should solve the problem without any 
backward-compatibiliy issues.

Original issue reported on code.google.com by rliesenf...@gmail.com on 9 Mar 2015 at 6:33

GoogleCodeExporter commented 8 years ago
Any idea when this issue might be addressed?

Original comment by rmcr...@gmail.com on 7 Jul 2015 at 2:47