Skip to content

Commit dc9a997

Browse files
committed
improve format of error messages relating to getters/setters
1 parent 1f6564d commit dc9a997

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,9 @@ public static Method findGetterMethod(Class containerClass, String propertyName)
485485
throw new PropertyNotFoundException(
486486
String.format(
487487
Locale.ROOT,
488-
"Could not locate getter method for property [%s#%s]",
489-
containerClass.getName(),
490-
propertyName
488+
"Could not locate getter method for property '%s' of class '%s'",
489+
propertyName,
490+
containerClass.getName()
491491
)
492492
);
493493
}
@@ -608,12 +608,11 @@ public static void checkGetAndIsVariants(
608608
throw new MappingException(
609609
String.format(
610610
Locale.ROOT,
611-
"In trying to locate getter for property [%s], Class [%s] defined " +
612-
"both a `get` [%s] and `is` [%s] variant",
613-
propertyName,
611+
"Class '%s' declares both 'get' [%s] and 'is' [%s] variants of getter for property '%s'",
614612
containerClass.getName(),
615-
getMethod.toString(),
616-
isMethod.toString()
613+
getMethod,
614+
isMethod,
615+
propertyName
617616
)
618617
);
619618
}
@@ -731,9 +730,9 @@ public static Method findSetterMethod(final Class containerClass, final String p
731730
throw new PropertyNotFoundException(
732731
String.format(
733732
Locale.ROOT,
734-
"Could not locate setter method for property [%s#%s]",
735-
containerClass.getName(),
736-
propertyName
733+
"Could not locate setter method for property '%s' of class '%s'",
734+
propertyName,
735+
containerClass.getName()
737736
)
738737
);
739738
}

hibernate-core/src/main/java/org/hibernate/property/access/internal/AccessStrategyHelper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,11 @@ private static void checkIsMethodVariant(
152152
throw new MappingException(
153153
String.format(
154154
Locale.ROOT,
155-
"In trying to locate getter for property [%s], Class [%s] defined " +
156-
"both a `get` [%s] and `is` [%s] variant",
157-
propertyName,
155+
"Class '%s' declares both 'get' [%s] and 'is' [%s] variants of getter for property '%s'",
158156
containerClass.getName(),
159157
method.toString(),
160-
isMethodVariant.toString()
158+
isMethodVariant,
159+
propertyName
161160
)
162161
);
163162
}

hibernate-core/src/test/java/org/hibernate/orm/test/property/GetAndIsVariantGetterTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.BeforeClass;
2626
import org.junit.Test;
2727

28+
import static org.hamcrest.CoreMatchers.endsWith;
2829
import static org.hamcrest.CoreMatchers.startsWith;
2930
import static org.junit.Assert.assertNotNull;
3031
import static org.junit.Assert.assertThat;
@@ -61,7 +62,7 @@ public void testHbmXml() {
6162
fail( "Expecting a failure" );
6263
}
6364
catch (MappingException e) {
64-
assertThat( e.getMessage(), startsWith( "In trying to locate getter for property [id]" ) );
65+
assertThat( e.getMessage(), endsWith( "variants of getter for property 'id'" ) );
6566
}
6667
}
6768

hibernate-core/src/test/java/org/hibernate/orm/test/proxy/MissingSetterWithEnhancementTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.hibernate.MappingException;
1414
import org.hibernate.SessionFactory;
1515
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
16-
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
1716
import org.hibernate.cfg.Configuration;
1817
import org.hibernate.cfg.Environment;
1918
import org.hibernate.service.ServiceRegistry;
@@ -64,7 +63,8 @@ public void testEnhancedClassMissesSetterForProperty() {
6463
}
6564
catch (MappingException e) {
6665
assertEquals(
67-
"Could not locate setter method for property [" + EntityWithMissingSetter.class.getName() + "#name]",
66+
"Could not locate setter method for property 'name' of class '"
67+
+ EntityWithMissingSetter.class.getName() + "'",
6868
e.getMessage()
6969
);
7070
}

0 commit comments

Comments
 (0)