diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java index 05e8e865e5..5b7a50a7e5 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java @@ -56,6 +56,11 @@ public class BytecodeProviderImpl implements BytecodeProvider { final String[] getterNames, final String[] setterNames, final Class[] types) { + if ( clazz.isInterface() || Modifier.isAbstract( clazz.getModifiers() ) ) { + // we don't provide an optimizer for interfaces and abstract classes - similar to what we do with Javassist + return null; + } + final Method[] getters = new Method[getterNames.length]; final Method[] setters = new Method[setterNames.length]; findAccessors( clazz, getterNames, setterNames, types, getters, setters ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/ReflectionOptimizerTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/ReflectionOptimizerTest.java index 2ec09c75e1..3d47fed608 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/ReflectionOptimizerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/ReflectionOptimizerTest.java @@ -6,17 +6,17 @@ */ package org.hibernate.test.bytecode; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import org.hibernate.bytecode.internal.javassist.BulkAccessor; import org.hibernate.bytecode.spi.BytecodeProvider; import org.hibernate.bytecode.spi.ReflectionOptimizer; import org.hibernate.cfg.Environment; - +import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import org.junit.Test; /** * @author Steve Ebersole @@ -55,10 +55,48 @@ public class ReflectionOptimizerTest extends BaseUnitTestCase { assertEquivalent( values, BeanReflectionHelper.TEST_VALUES ); } + @Test + @TestForIssue(jiraKey = "HHH-12584") + public void testAbstractClass() { + BytecodeProvider provider = Environment.getBytecodeProvider(); + ReflectionOptimizer reflectionOptimizer = provider.getReflectionOptimizer( AbstractClass.class, new String[]{ "getProperty" }, + new String[]{ "setProperty" }, new Class[]{ String.class } ); + assertNull( reflectionOptimizer ); + } + + @Test + @TestForIssue(jiraKey = "HHH-12584") + public void testInterface() { + BytecodeProvider provider = Environment.getBytecodeProvider(); + ReflectionOptimizer reflectionOptimizer = provider.getReflectionOptimizer( Interface.class, new String[]{ "getProperty" }, + new String[]{ "setProperty" }, new Class[]{ String.class } ); + assertNull( reflectionOptimizer ); + } + private void assertEquivalent(Object[] checkValues, Object[] values) { assertEquals( "Different lengths", checkValues.length, values.length ); for ( int i = 0; i < checkValues.length; i++ ) { assertEquals( "different values at index [" + i + "]", checkValues[i], values[i] ); } } + + public static abstract class AbstractClass { + + private String property; + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + } + + public interface Interface { + + String getProperty(); + + void setProperty(String property); + } }