From 88b1e33d72d3843556a3ce043ad603c4746f2283 Mon Sep 17 00:00:00 2001 From: "Archie L. Cobbs" Date: Mon, 23 Oct 2017 15:30:05 -0500 Subject: [PATCH] HHH-12046 - Don't consider static methods for isFoo()/getFoo() conflicts. --- .../internal/util/ReflectHelper.java | 8 +++- .../property/GetAndIsVariantGetterTest.java | 44 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java index df03e67266..68bc67d286 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java @@ -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 ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/property/GetAndIsVariantGetterTest.java b/hibernate-core/src/test/java/org/hibernate/property/GetAndIsVariantGetterTest.java index d0762c1d80..86ffd4a585 100644 --- a/hibernate-core/src/test/java/org/hibernate/property/GetAndIsVariantGetterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/property/GetAndIsVariantGetterTest.java @@ -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; + } + } }