HHH-12584 Do not try to create a reflection optimizer for interfaces and abstract classes
It's already the behavior of the Javassist bytecode provider but the ByteBuddy one was failing with an exception.
This commit is contained in:
parent
8b2bf61eb1
commit
93fed78f31
|
@ -53,6 +53,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 );
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue