HHH-12046 - Don't consider static methods for isFoo()/getFoo() conflicts.

This commit is contained in:
Archie L. Cobbs 2017-10-23 15:30:05 -05:00 committed by Vlad Mihalcea
parent ce21f133d2
commit 88b1e33d72
2 changed files with 50 additions and 2 deletions

View File

@ -457,6 +457,10 @@ public final class ReflectHelper {
continue;
}
if ( Modifier.isStatic( method.getModifiers() ) ) {
continue;
}
final String methodName = method.getName();
// try "get"
@ -492,7 +496,7 @@ public final class ReflectHelper {
// verify that the Class does not also define a method with the same stem name with 'is'
try {
final Method isMethod = containerClass.getDeclaredMethod( "is" + stemName );
if ( isMethod.getAnnotation( Transient.class ) == null ) {
if ( !Modifier.isStatic( isMethod.getModifiers() ) && isMethod.getAnnotation( Transient.class ) == null ) {
// No such method should throw the caught exception. So if we get here, there was
// such a method.
checkGetAndIsVariants( containerClass, propertyName, getMethod, isMethod );
@ -534,7 +538,7 @@ public final class ReflectHelper {
final Method getMethod = containerClass.getDeclaredMethod( "get" + stemName );
// No such method should throw the caught exception. So if we get here, there was
// such a method.
if ( getMethod.getAnnotation( Transient.class ) == null ) {
if ( !Modifier.isStatic( getMethod.getModifiers() ) && getMethod.getAnnotation( Transient.class ) == null ) {
checkGetAndIsVariants( containerClass, propertyName, getMethod, isMethod );
}
}

View File

@ -17,6 +17,7 @@ import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.testing.TestForIssue;
import org.junit.AfterClass;
@ -26,6 +27,7 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
@ -97,6 +99,18 @@ public class GetAndIsVariantGetterTest {
assertNotNull( metadata.getEntityBinding( AnotherEntity.class.getName() ).getIdentifierProperty() );
}
@Test
@TestForIssue( jiraKey = "HHH-12046" )
public void testInstanceStaticConflict() {
Metadata metadata = new MetadataSources( ssr )
.addAnnotatedClass( InstanceStaticEntity.class )
.buildMetadata();
assertNotNull( metadata.getEntityBinding( InstanceStaticEntity.class.getName() ).getIdentifier() );
assertNotNull( metadata.getEntityBinding( InstanceStaticEntity.class.getName() ).getIdentifierProperty() );
assertTrue( metadata.getEntityBinding( InstanceStaticEntity.class.getName() ).hasProperty("foo") );
ReflectHelper.findGetterMethod( InstanceStaticEntity.class, "foo" );
}
@Entity
public static class TheEntity {
private Integer id;
@ -153,4 +167,34 @@ public class GetAndIsVariantGetterTest {
this.id = id;
}
}
@Entity
public static class InstanceStaticEntity {
private Integer id;
private boolean foo;
@Id
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public boolean isFoo() {
return this.foo;
}
public void setFoo(boolean foo) {
this.foo = foo;
}
public static Object getFoo() {
return null;
}
public static boolean isId() {
return false;
}
}
}