diff --git a/hibernate-core/src/main/java/org/hibernate/InstantiationException.java b/hibernate-core/src/main/java/org/hibernate/InstantiationException.java index b7dc23a989..fc63632bf9 100644 --- a/hibernate-core/src/main/java/org/hibernate/InstantiationException.java +++ b/hibernate-core/src/main/java/org/hibernate/InstantiationException.java @@ -27,7 +27,7 @@ public class InstantiationException extends HibernateException { } /** - * Constructs a InstantiationException. + * Constructs an {@code InstantiationException}. * * @param message A message explaining the exception condition * @param clazz The Class we are attempting to instantiate @@ -37,7 +37,7 @@ public class InstantiationException extends HibernateException { } /** - * Constructs a InstantiationException. + * Constructs an {@code InstantiationException}. * * @param message A message explaining the exception condition * @param clazz The Class we are attempting to instantiate @@ -49,7 +49,7 @@ public class InstantiationException extends HibernateException { } /** - * Returns the Class we were attempting to instantiate. + * Returns the {@link Class} we were attempting to instantiate. * * @return The class we are unable to instantiate */ @@ -59,7 +59,9 @@ public class InstantiationException extends HibernateException { @Override public String getMessage() { - return super.getMessage() + " '" + clazz.getName() + "'"; + final String message = super.getMessage() + " '" + clazz.getName() + "'"; + final Throwable cause = getCause(); + return cause != null ? message + " due to: " + cause.getMessage() : message; } } diff --git a/hibernate-core/src/main/java/org/hibernate/PropertyAccessException.java b/hibernate-core/src/main/java/org/hibernate/PropertyAccessException.java index 5fb7bff5f1..82237d3e3c 100644 --- a/hibernate-core/src/main/java/org/hibernate/PropertyAccessException.java +++ b/hibernate-core/src/main/java/org/hibernate/PropertyAccessException.java @@ -6,7 +6,7 @@ */ package org.hibernate; -import org.hibernate.internal.util.StringHelper; +import static org.hibernate.internal.util.StringHelper.qualify; /** * A problem occurred accessing a property of an instance of a @@ -64,7 +64,7 @@ public class PropertyAccessException extends HibernateException { @Override public String getMessage() { return originalMessage() - + " : `" + StringHelper.qualify( persistentClass.getName(), propertyName ) - + ( wasSetter ? "` (setter)" : "` (getter)" ); + + ": '" + qualify( persistentClass.getName(), propertyName ) + "'" + + ( wasSetter ? " (setter)" : " (getter)" ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryConstructorTransformer.java b/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryConstructorTransformer.java index 01c95001c8..b9414bae99 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryConstructorTransformer.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryConstructorTransformer.java @@ -48,7 +48,7 @@ public class NativeQueryConstructorTransformer implements TupleTransformer } } catch (Exception e) { - throw new InstantiationException( "Cannot instantiate query result type ", resultClass, e ); + throw new InstantiationException( "Cannot instantiate query result type", resultClass, e ); } if ( constructor == null ) { throw new InstantiationException( "Result class must have a single constructor with exactly " diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/property/access/spi/GetterMethodImplTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/property/access/spi/GetterMethodImplTest.java index e8f8e1eabd..e9a72381f3 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/property/access/spi/GetterMethodImplTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/property/access/spi/GetterMethodImplTest.java @@ -83,14 +83,14 @@ public class GetterMethodImplTest { Getter runtimeException = getter( TargetThrowingExceptions.class, "runtimeException" ); assertThatThrownBy( () -> runtimeException.get( target ) ) .isInstanceOf( PropertyAccessException.class ) - .hasMessage( "Exception occurred inside : `" + TargetThrowingExceptions.class.getName() +".runtimeException` (getter)" ) + .hasMessage( "Exception occurred inside: '" + TargetThrowingExceptions.class.getName() +".runtimeException' (getter)" ) .getCause() // Not the root cause, the *direct* cause! We don't want extra wrapping. .isExactlyInstanceOf( RuntimeException.class ); Getter checkedException = getter( TargetThrowingExceptions.class, "checkedException" ); assertThatThrownBy( () -> checkedException.get( target ) ) .isInstanceOf( PropertyAccessException.class ) - .hasMessage( "Exception occurred inside : `" + TargetThrowingExceptions.class.getName() +".checkedException` (getter)" ) + .hasMessage( "Exception occurred inside: '" + TargetThrowingExceptions.class.getName() +".checkedException' (getter)" ) .getCause() // Not the root cause, the *direct* cause! We don't want extra wrapping. .isExactlyInstanceOf( Exception.class ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/property/access/spi/SetterMethodImplTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/property/access/spi/SetterMethodImplTest.java index 87db8e733d..60f9f8160e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/property/access/spi/SetterMethodImplTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/property/access/spi/SetterMethodImplTest.java @@ -86,14 +86,14 @@ public class SetterMethodImplTest { Setter runtimeException = setter( TargetThrowingExceptions.class, "runtimeException", String.class ); assertThatThrownBy( () -> runtimeException.set( target, "foo" ) ) .isInstanceOf( PropertyAccessException.class ) - .hasMessage( "Exception occurred inside : `" + TargetThrowingExceptions.class.getName() +".runtimeException` (setter)" ) + .hasMessage( "Exception occurred inside: '" + TargetThrowingExceptions.class.getName() +".runtimeException' (setter)" ) .getCause() // Not the root cause, the *direct* cause! We don't want extra wrapping. .isExactlyInstanceOf( RuntimeException.class ); Setter checkedException = setter( TargetThrowingExceptions.class, "checkedException", String.class ); assertThatThrownBy( () -> checkedException.set( target, "foo" ) ) .isInstanceOf( PropertyAccessException.class ) - .hasMessage( "Exception occurred inside : `" + TargetThrowingExceptions.class.getName() +".checkedException` (setter)" ) + .hasMessage( "Exception occurred inside: '" + TargetThrowingExceptions.class.getName() +".checkedException' (setter)" ) .getCause() // Not the root cause, the *direct* cause! We don't want extra wrapping. .isExactlyInstanceOf( Exception.class );