Skip to content

Commit

Permalink
[OPENJPA-2923] replace new Long(long) with Long.valueOf(long) while e…
Browse files Browse the repository at this point in the history
…nhancing (#117)
  • Loading branch information
solomax authored Jul 15, 2024
1 parent b3d1ef8 commit c3fff2c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
Expand Down Expand Up @@ -149,6 +150,10 @@ public class PCEnhancer {

private static final AuxiliaryEnhancer[] _auxEnhancers;

private static final Method LONG_VALUE_OF = Stream.of(Long.class.getDeclaredMethods())
.filter(m -> "valueOf".equals(m.getName()) && long.class == m.getParameterTypes()[0])
.findAny().get();

static {
Class[] classes = Services.getImplementorClasses(
AuxiliaryEnhancer.class,
Expand Down Expand Up @@ -2834,7 +2839,7 @@ private void addCopyKeyFieldsFromObjectIdMethod(boolean fieldManager) throws NoS
instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); // this
}

if (unwrapped != type) {
if (unwrapped != type && type != Long.class) {
instructions.add(new TypeInsnNode(Opcodes.NEW, Type.getInternalName(type)));
instructions.add(new InsnNode(Opcodes.DUP));
}
Expand Down Expand Up @@ -2865,10 +2870,17 @@ else if (oidType == DateId.class) {
"getId",
Type.getMethodDescriptor(Type.getType(unwrapped))));
if (unwrapped != type) {
instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,
Type.getInternalName(type),
"<init>",
Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(unwrapped))));
if (type == Long.class) {
instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
Type.getInternalName(type),
LONG_VALUE_OF.getName(),
Type.getMethodDescriptor(LONG_VALUE_OF)));
} else {
instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,
Type.getInternalName(type),
"<init>",
Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(unwrapped))));
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions openjpa-tools/openjpa-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${min.maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${min.maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
Expand Down

0 comments on commit c3fff2c

Please sign in to comment.