HHH-12090 - PropertyAccessBuildingException: Could not locate setter for property named XXX for Java 8 default methods
This commit is contained in:
parent
db259df457
commit
14a9c0a56d
|
@ -422,13 +422,15 @@ public final class ReflectHelper {
|
|||
}
|
||||
|
||||
getter = getGetterOrNull( checkClass, propertyName );
|
||||
|
||||
// if no getter found yet, check all implemented interfaces
|
||||
if ( getter == null ) {
|
||||
getter = getGetterOrNull( checkClass.getInterfaces(), propertyName );
|
||||
}
|
||||
|
||||
checkClass = checkClass.getSuperclass();
|
||||
}
|
||||
|
||||
// if no getter found yet, check all implemented interfaces
|
||||
if ( getter == null ) {
|
||||
getter = getGetterOrNull( containerClass.getInterfaces(), propertyName );
|
||||
}
|
||||
|
||||
if ( getter == null ) {
|
||||
throw new PropertyNotFoundException(
|
||||
|
@ -584,21 +586,16 @@ public final class ReflectHelper {
|
|||
}
|
||||
|
||||
setter = setterOrNull( checkClass, propertyName, propertyType );
|
||||
checkClass = checkClass.getSuperclass();
|
||||
}
|
||||
|
||||
// if no setter found yet, check all implemented interfaces
|
||||
if ( setter == null ) {
|
||||
setter = setterOrNull( containerClass.getInterfaces(), propertyName, propertyType );
|
||||
// for ( Class theInterface : containerClass.getInterfaces() ) {
|
||||
// setter = setterOrNull( theInterface, propertyName, propertyType );
|
||||
// if ( setter != null ) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
else {
|
||||
ensureAccessibility( setter );
|
||||
// if no setter found yet, check all implemented interfaces
|
||||
if ( setter == null ) {
|
||||
setter = setterOrNull( checkClass.getInterfaces(), propertyName, propertyType );
|
||||
}
|
||||
else {
|
||||
ensureAccessibility( setter );
|
||||
}
|
||||
|
||||
checkClass = checkClass.getSuperclass();
|
||||
}
|
||||
return setter; // might be null
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.internal.util;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.persistence.FetchType;
|
||||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
|
@ -14,11 +16,15 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|||
import org.hibernate.internal.util.hib3rnat3.C0nst4nts३;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static java.lang.Integer.valueOf;
|
||||
import static org.hibernate.internal.util.ReflectHelperTest.Status.OFF;
|
||||
import static org.hibernate.internal.util.ReflectHelperTest.Status.ON;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
@ -40,8 +46,17 @@ public class ReflectHelperTest {
|
|||
}
|
||||
|
||||
interface A {
|
||||
|
||||
Integer getId();
|
||||
void setId(Integer id);
|
||||
|
||||
default Status getStatus(){
|
||||
return ON;
|
||||
}
|
||||
|
||||
default void setId(String id){
|
||||
this.setId(valueOf(id));
|
||||
}
|
||||
}
|
||||
|
||||
interface B extends A {
|
||||
|
@ -79,6 +94,11 @@ public class ReflectHelperTest {
|
|||
|
||||
}
|
||||
|
||||
class F extends D {
|
||||
public Status getStatus(){
|
||||
return OFF;
|
||||
}
|
||||
}
|
||||
|
||||
private SessionFactoryImplementor sessionFactoryImplementorMock;
|
||||
|
||||
|
@ -163,7 +183,7 @@ public class ReflectHelperTest {
|
|||
when( sessionFactoryOptionsMock.isConventionalJavaConstants() ).thenReturn( true );
|
||||
when( classLoaderServiceMock.classForName( "org.hibernate.internal.util.ReflectHelperTest$Status" ) ).thenReturn( (Class) Status.class );
|
||||
Object value = ReflectHelper.getConstantValue( "org.hibernate.internal.util.ReflectHelperTest$Status.ON", sessionFactoryImplementorMock);
|
||||
assertEquals( Status.ON, value );
|
||||
assertEquals( ON, value );
|
||||
verify(classLoaderServiceMock, times(1)).classForName( eq("org.hibernate.internal.util.ReflectHelperTest$Status") );
|
||||
}
|
||||
|
||||
|
@ -191,4 +211,23 @@ public class ReflectHelperTest {
|
|||
public void test_setMethod_nestedInterfaces() {
|
||||
assertNotNull( ReflectHelper.findSetterMethod( C.class, "id", Integer.class ) );
|
||||
}
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-12090")
|
||||
@Test
|
||||
public void test_getMethod_nestedInterfaces_on_superclasses()
|
||||
throws InvocationTargetException, IllegalAccessException {
|
||||
Method statusMethodEClass = ReflectHelper.findGetterMethod( E.class, "status" );
|
||||
assertNotNull(statusMethodEClass);
|
||||
assertEquals( ON, statusMethodEClass.invoke( new E() ) );
|
||||
|
||||
Method statusMethodFClass = ReflectHelper.findGetterMethod( F.class, "status" );
|
||||
assertNotNull(statusMethodFClass);
|
||||
assertEquals( OFF, statusMethodFClass.invoke( new F() ) );
|
||||
}
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-12090")
|
||||
@Test
|
||||
public void test_setMethod_nestedInterfaces_on_superclasses() {
|
||||
assertNotNull( ReflectHelper.findSetterMethod( E.class, "id", String.class ) );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue