OPENJPA-2821 use AsmAdapter for subclassing

to write proper java8 code
This commit is contained in:
Mark Struberg 2020-07-23 14:05:56 +02:00
parent ab6e0ed4b4
commit 94a033d83b
2 changed files with 20 additions and 1 deletions

View File

@ -81,6 +81,20 @@ public final class AsmAdaptor {
}
}
public static void write(BCClass bc, OutputStream os) throws IOException {
if (bc.getMajorVersion() < Java7_MajorVersion) {
bc.write(os);
}
else {
try {
writeJava7(bc, os);
} finally {
os.flush();
os.close();
}
}
}
public static byte[] toByteArray(BCClass bc, byte[] returnBytes) throws IOException {
if (bc.getMajorVersion() >= Java7_MajorVersion) {
returnBytes = toJava7ByteArray(bc, returnBytes);

View File

@ -18,6 +18,7 @@
*/
package org.apache.openjpa.enhance;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@ -142,6 +143,8 @@ public class ManagedClassSubclasser {
if (redefine) {
enhancer.setRedefine(true);
}
// we need to create subclasses because class retransform doesn't allow to change the interfaces of a previously loaded class
enhancer.setCreateSubclass(true);
enhancer.setAddDefaultConstructor(true);
@ -276,7 +279,9 @@ public class ManagedClassSubclasser {
if (enhancer.isAlreadyRedefined())
ints.add(bc.getType());
else {
map.put(bc.getType(), bc.toByteArray());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
AsmAdaptor.write(bc, baos);
map.put(bc.getType(), baos.toByteArray());
debugBytecodes(bc);
}
} else {