This is an automated email from the ASF dual-hosted git repository. solomax pushed a commit to branch replace-Long-new-long in repository https://gitbox.apache.org/repos/asf/openjpa.git
commit ff7f5072b8356ae79153b36bf4516a29ac27ad51 Author: Maxim Solodovnik <solo...@apache.org> AuthorDate: Thu Jul 11 10:55:53 2024 +0700 [OPENJPA-2923] replace new Long(long) with Long.valueOf(long) while enhancing --- .../org/apache/openjpa/enhance/PCEnhancer.java | 22 +++++++++++++++++----- openjpa-tools/openjpa-maven-plugin/pom.xml | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java index 65c560925..6fd062dfb 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java @@ -56,6 +56,7 @@ import java.util.Properties; 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; @@ -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, @@ -2834,7 +2839,7 @@ public class PCEnhancer { 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)); } @@ -2865,10 +2870,17 @@ public class PCEnhancer { "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)))); + } } } } diff --git a/openjpa-tools/openjpa-maven-plugin/pom.xml b/openjpa-tools/openjpa-maven-plugin/pom.xml index 6d6081df1..db5cb381f 100644 --- a/openjpa-tools/openjpa-maven-plugin/pom.xml +++ b/openjpa-tools/openjpa-maven-plugin/pom.xml @@ -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>