From b5ecb8dd92a568843cc91ba1f6b1cddd0c36f337 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Fri, 23 Nov 2018 21:36:58 +1100 Subject: [PATCH] Fix gizmp return type issue --- .../protean/gizmo/BytecodeCreatorImpl.java | 8 ++--- .../gizmo/PrimitiveReturnTypeTestCase.java | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 ext/gizmo/src/test/java/org/jboss/protean/gizmo/PrimitiveReturnTypeTestCase.java diff --git a/ext/gizmo/src/main/java/org/jboss/protean/gizmo/BytecodeCreatorImpl.java b/ext/gizmo/src/main/java/org/jboss/protean/gizmo/BytecodeCreatorImpl.java index c70a29d4a9a2a..18bf81774657f 100644 --- a/ext/gizmo/src/main/java/org/jboss/protean/gizmo/BytecodeCreatorImpl.java +++ b/ext/gizmo/src/main/java/org/jboss/protean/gizmo/BytecodeCreatorImpl.java @@ -772,13 +772,13 @@ public void writeBytecode(MethodVisitor methodVisitor) { methodVisitor.visitInsn(Opcodes.RETURN); } else { loadResultHandle(methodVisitor, resolvedReturnValue, BytecodeCreatorImpl.this, methodDescriptor.getReturnType()); - if (resolvedReturnValue.getType().equals("S") || resolvedReturnValue.getType().equals("Z") || resolvedReturnValue.getType().equals("I") || resolvedReturnValue.getType().equals("B")) { + if (methodDescriptor.getReturnType().equals("S") || methodDescriptor.getReturnType().equals("Z") || methodDescriptor.getReturnType().equals("I") || methodDescriptor.getReturnType().equals("B")) { methodVisitor.visitInsn(Opcodes.IRETURN); - } else if (resolvedReturnValue.getType().equals("J")) { + } else if (methodDescriptor.getReturnType().equals("J")) { methodVisitor.visitInsn(Opcodes.LRETURN); - } else if (resolvedReturnValue.getType().equals("F")) { + } else if (methodDescriptor.getReturnType().equals("F")) { methodVisitor.visitInsn(Opcodes.FRETURN); - } else if (resolvedReturnValue.getType().equals("D")) { + } else if (methodDescriptor.getReturnType().equals("D")) { methodVisitor.visitInsn(Opcodes.DRETURN); } else { methodVisitor.visitInsn(Opcodes.ARETURN); diff --git a/ext/gizmo/src/test/java/org/jboss/protean/gizmo/PrimitiveReturnTypeTestCase.java b/ext/gizmo/src/test/java/org/jboss/protean/gizmo/PrimitiveReturnTypeTestCase.java new file mode 100644 index 0000000000000..76619b21ae976 --- /dev/null +++ b/ext/gizmo/src/test/java/org/jboss/protean/gizmo/PrimitiveReturnTypeTestCase.java @@ -0,0 +1,35 @@ +/* + * Copyright 2018 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.protean.gizmo; + +import org.junit.Test; +import org.objectweb.asm.Opcodes; + +public class PrimitiveReturnTypeTestCase { + + @Test + public void testPrimitiveReturnType() throws Exception { + TestClassLoader cl = new TestClassLoader(getClass().getClassLoader()); + try (ClassCreator creator = ClassCreator.builder().classOutput(cl).className("com.MyTest").build()) { + MethodCreator method = creator.getMethodCreator("transform", Object.class).setModifiers(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC); + ResultHandle ret = method.readStaticField(FieldDescriptor.of(Integer.class, "MAX_VALUE", int.class)); + method.returnValue(ret); + } + Class clazz = cl.loadClass("com.MyTest"); + clazz.getMethod("transform").invoke(null); + } +} \ No newline at end of file