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

[OPENJPA-2923] replace new Long(long) with Long.valueOf(long) while enhancing #117

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading