From 7df56daddad2a76bf033e9c9434614bd46129677 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 30 Oct 2024 12:06:20 +0100 Subject: [PATCH] more work on flow typing in the JavaTypes Signed-off-by: Gavin King --- .../type/descriptor/java/ArrayJavaType.java | 23 ++++----- .../type/descriptor/java/BasicJavaType.java | 4 +- .../type/descriptor/java/BlobJavaType.java | 14 ++---- .../type/descriptor/java/BooleanJavaType.java | 11 ++--- .../java/BooleanPrimitiveArrayJavaType.java | 19 ++++---- .../descriptor/java/ByteArrayJavaType.java | 2 +- .../type/descriptor/java/ByteJavaType.java | 48 +++++++++---------- .../descriptor/java/CalendarDateJavaType.java | 16 +++---- .../descriptor/java/CalendarJavaType.java | 15 +++--- .../descriptor/java/CalendarTimeJavaType.java | 16 +++---- .../java/CharacterArrayJavaType.java | 18 +++---- .../type/descriptor/java/ClobJavaType.java | 14 ++---- .../type/descriptor/java/DateJavaType.java | 12 ++--- .../type/descriptor/java/DoubleJavaType.java | 48 +++++++------------ .../java/DoublePrimitiveArrayJavaType.java | 19 ++++---- .../type/descriptor/java/FloatJavaType.java | 44 ++++------------- .../java/FloatPrimitiveArrayJavaType.java | 19 ++++---- .../descriptor/java/InetAddressJavaType.java | 12 ++--- .../type/descriptor/java/IntegerJavaType.java | 48 +++++++++---------- .../java/IntegerPrimitiveArrayJavaType.java | 19 ++++---- .../descriptor/java/JdbcDateJavaType.java | 20 ++++---- .../descriptor/java/JdbcTimeJavaType.java | 19 ++++---- .../java/JdbcTimestampJavaType.java | 20 ++++---- .../type/descriptor/java/LocaleJavaType.java | 8 ++-- .../type/descriptor/java/LongJavaType.java | 48 +++++++++---------- .../java/LongPrimitiveArrayJavaType.java | 19 ++++---- .../type/descriptor/java/NClobJavaType.java | 11 ++--- .../descriptor/java/ObjectArrayJavaType.java | 4 +- .../java/PrimitiveByteArrayJavaType.java | 6 +-- .../java/PrimitiveCharacterArrayJavaType.java | 22 ++++----- .../type/descriptor/java/ShortJavaType.java | 48 +++++++++---------- .../java/ShortPrimitiveArrayJavaType.java | 19 ++++---- .../type/descriptor/java/UrlJavaType.java | 3 +- 33 files changed, 306 insertions(+), 362 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ArrayJavaType.java index 106d2ef614..5e06292a45 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ArrayJavaType.java @@ -296,8 +296,7 @@ public class ArrayJavaType extends AbstractArrayJavaType { } } - if ( value instanceof Object[] ) { - final Object[] raw = (Object[]) value; + if ( value instanceof Object[] raw ) { final Class componentClass = getElementJavaType().getJavaTypeClass(); //noinspection unchecked final T[] wrapped = (T[]) java.lang.reflect.Array.newInstance( componentClass, raw.length ); @@ -314,12 +313,12 @@ public class ArrayJavaType extends AbstractArrayJavaType { } return wrapped; } - else if ( value instanceof byte[] ) { - return fromBytes( (byte[]) value ); + else if ( value instanceof byte[] bytes ) { + return fromBytes( bytes ); } - else if ( value instanceof BinaryStream ) { + else if ( value instanceof BinaryStream binaryStream ) { // When the value is a BinaryStream, this is a deserialization request - return fromBytes( ( (BinaryStream) value ).getBytes() ); + return fromBytes( binaryStream.getBytes() ); } else if ( getElementJavaType().isInstance( value ) ) { // Support binding a single element as parameter value @@ -329,8 +328,7 @@ public class ArrayJavaType extends AbstractArrayJavaType { wrapped[0] = (T) value; return wrapped; } - else if ( value instanceof Collection ) { - final Collection collection = (Collection) value; + else if ( value instanceof Collection collection ) { //noinspection unchecked final T[] wrapped = (T[]) java.lang.reflect.Array.newInstance( getElementJavaType().getJavaTypeClass(), collection.size() ); int i = 0; @@ -359,9 +357,8 @@ public class ArrayJavaType extends AbstractArrayJavaType { } } - private T[] fromBytes(byte[] value) { - Class elementClass = getElementJavaType().getJavaTypeClass(); - byte[] bytes = value; + private T[] fromBytes(byte[] bytes) { + final Class elementClass = getElementJavaType().getJavaTypeClass(); if ( elementClass.isEnum() ) { final Object[] array = (Object[]) Array.newInstance( elementClass, bytes.length ); for (int i = 0; i < bytes.length; i++ ) { @@ -375,7 +372,7 @@ public class ArrayJavaType extends AbstractArrayJavaType { else { // When the value is a byte[], this is a deserialization request //noinspection unchecked - return (T[]) SerializationHelper.deserialize(value); + return (T[]) SerializationHelper.deserialize(bytes); } } @@ -400,7 +397,7 @@ public class ArrayJavaType extends AbstractArrayJavaType { return null; } //noinspection unchecked - T[] copy = (T[]) Array.newInstance( componentClass, value.length ); + final T[] copy = (T[]) Array.newInstance( componentClass, value.length ); for ( int i = 0; i < value.length; i ++ ) { copy[ i ] = componentPlan.deepCopy( value[ i ] ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BasicJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BasicJavaType.java index bba75a6f0e..e598f66743 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BasicJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BasicJavaType.java @@ -27,8 +27,8 @@ public interface BasicJavaType extends JavaType { // match legacy behavior int jdbcTypeCode = JdbcTypeJavaClassMappings.INSTANCE.determineJdbcTypeCodeForJavaClass( getJavaTypeClass() ); final JdbcType descriptor = indicators.getJdbcType( indicators.resolveJdbcTypeCode( jdbcTypeCode ) ); - return descriptor instanceof AdjustableJdbcType - ? ( (AdjustableJdbcType) descriptor ).resolveIndicatedType( indicators, this ) + return descriptor instanceof AdjustableJdbcType adjustableJdbcType + ? adjustableJdbcType.resolveIndicatedType( indicators, this ) : descriptor; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BlobJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BlobJavaType.java index db45a657d1..a586edadc9 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BlobJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BlobJavaType.java @@ -163,17 +163,13 @@ public class BlobJavaType extends AbstractClassJavaType { if ( value == null ) { return null; } - - // Support multiple return types from - // org.hibernate.type.descriptor.sql.BlobTypeDescriptor - if ( Blob.class.isAssignableFrom( value.getClass() ) ) { - return options.getLobCreator().wrap( (Blob) value ); + else if ( value instanceof Blob blob ) { + return options.getLobCreator().wrap( blob ); } - else if ( byte[].class.isAssignableFrom( value.getClass() ) ) { - return options.getLobCreator().createBlob( ( byte[] ) value); + else if ( value instanceof byte[] bytes ) { + return options.getLobCreator().createBlob( bytes ); } - else if ( InputStream.class.isAssignableFrom( value.getClass() ) ) { - InputStream inputStream = ( InputStream ) value; + else if ( value instanceof InputStream inputStream ) { try { return options.getLobCreator().createBlob( inputStream, inputStream.available() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java index 770903bd95..a4797a3ce5 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java @@ -112,8 +112,7 @@ public class BooleanJavaType extends AbstractClassJavaType implements return booleanValue; } if (value instanceof Number number) { - final int intValue = number.intValue(); - return intValue != 0; + return number.intValue() != 0; } if (value instanceof Character character) { return isTrue( character ); @@ -192,7 +191,7 @@ public class BooleanJavaType extends AbstractClassJavaType implements if ( converter != null ) { if ( jdbcType.isString() ) { @SuppressWarnings("unchecked") - BasicValueConverter stringConverter = + final BasicValueConverter stringConverter = (BasicValueConverter) converter; final Object falseValue = stringConverter.toRelationalValue( false ); final Object trueValue = stringConverter.toRelationalValue( true ); @@ -201,11 +200,11 @@ public class BooleanJavaType extends AbstractClassJavaType implements } else if ( jdbcType.isInteger() ) { @SuppressWarnings("unchecked") - BasicValueConverter numericConverter = + final BasicValueConverter numericConverter = (BasicValueConverter) converter; final Number falseValue = numericConverter.toRelationalValue( false ); final Number trueValue = numericConverter.toRelationalValue( true ); - Long[] values = getPossibleNumericValues( numericConverter, falseValue, trueValue ); + final Long[] values = getPossibleNumericValues( numericConverter, falseValue, trueValue ); return dialect.getCheckCondition( columnName, values ); } } @@ -222,7 +221,7 @@ public class BooleanJavaType extends AbstractClassJavaType implements } catch ( NullPointerException ignored ) { } - Long[] values = new Long[nullValue != null ? 3 : 2]; + final Long[] values = new Long[nullValue != null ? 3 : 2]; values[0] = falseValue != null ? falseValue.longValue() : null; values[1] = trueValue != null ? trueValue.longValue() : null; if ( nullValue != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanPrimitiveArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanPrimitiveArrayJavaType.java index e12f78a3a5..30aea2bf22 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanPrimitiveArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanPrimitiveArrayJavaType.java @@ -149,16 +149,16 @@ public class BooleanPrimitiveArrayJavaType extends AbstractArrayJavaType ) { - final Collection collection = (Collection) value; + else if ( value instanceof Collection collection ) { final boolean[] wrapped = new boolean[collection.size()]; int i = 0; for ( Object e : collection ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayJavaType.java index 4f44700be1..6e6582fec9 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayJavaType.java @@ -35,7 +35,7 @@ public class ByteArrayJavaType extends AbstractClassJavaType { @Override public boolean areEqual(Byte[] one, Byte[] another) { return one == another - || ( one != null && another != null && Arrays.equals(one, another) ); + || one != null && another != null && Arrays.equals(one, another); } @Override public int extractHashCode(Byte[] bytes) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteJavaType.java index 781ddd50f6..87e4f609e1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteJavaType.java @@ -79,14 +79,14 @@ public class ByteJavaType extends AbstractClassJavaType if ( value == null ) { return null; } - if ( value instanceof Byte ) { - return (Byte) value; + if ( value instanceof Byte byteValue ) { + return byteValue; } - if ( value instanceof Number ) { - return ( (Number) value ).byteValue(); + if ( value instanceof Number number ) { + return number.byteValue(); } - if ( value instanceof String ) { - return Byte.valueOf( ( (String) value ) ); + if ( value instanceof String string ) { + return Byte.valueOf( string ); } throw unknownWrap( value.getClass() ); } @@ -132,41 +132,41 @@ public class ByteJavaType extends AbstractClassJavaType return null; } - if ( value instanceof Byte ) { - return (Byte) value; + if ( value instanceof Byte byteValue ) { + return byteValue; } - if ( value instanceof Short ) { - return CoercionHelper.toByte( (Short) value ); + if ( value instanceof Short shotValue ) { + return CoercionHelper.toByte( shotValue ); } - if ( value instanceof Integer ) { - return CoercionHelper.toByte( (Integer) value ); + if ( value instanceof Integer integerValue ) { + return CoercionHelper.toByte( integerValue ); } - if ( value instanceof Long ) { - return CoercionHelper.toByte( (Long) value ); + if ( value instanceof Long longValue ) { + return CoercionHelper.toByte( longValue ); } - if ( value instanceof Double ) { - return CoercionHelper.toByte( (Double) value ); + if ( value instanceof Double doubleValue ) { + return CoercionHelper.toByte( doubleValue ); } - if ( value instanceof Float ) { - return CoercionHelper.toByte( (Float) value ); + if ( value instanceof Float floatValue ) { + return CoercionHelper.toByte( floatValue ); } - if ( value instanceof BigInteger ) { - return CoercionHelper.toByte( (BigInteger) value ); + if ( value instanceof BigInteger bigInteger ) { + return CoercionHelper.toByte( bigInteger ); } - if ( value instanceof BigDecimal ) { - return CoercionHelper.toByte( (BigDecimal) value ); + if ( value instanceof BigDecimal bigDecimal ) { + return CoercionHelper.toByte( bigDecimal ); } - if ( value instanceof String ) { + if ( value instanceof String string ) { return CoercionHelper.coerceWrappingError( - () -> Byte.parseByte( (String) value ) + () -> Byte.parseByte( string ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaType.java index 7e8961454e..940c5201a5 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaType.java @@ -115,17 +115,17 @@ public class CalendarDateJavaType extends AbstractTemporalJavaType { if ( value == null ) { return null; } - if (value instanceof Calendar) { - return (Calendar) value; + else if (value instanceof Calendar calendar) { + return calendar; } - - if ( !(value instanceof Date)) { + else if ( value instanceof Date date ) { + final Calendar cal = new GregorianCalendar(); + cal.setTime( date ); + return cal; + } + else { throw unknownWrap( value.getClass() ); } - - Calendar cal = new GregorianCalendar(); - cal.setTime( (Date) value ); - return cal; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaType.java index 26789ccdf1..e4d49d274f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaType.java @@ -132,17 +132,18 @@ public class CalendarJavaType extends AbstractTemporalJavaType impleme if ( value == null ) { return null; } - if (value instanceof Calendar) { - return (Calendar) value; + else if (value instanceof Calendar calendar) { + return calendar; } - - if ( !(value instanceof java.util.Date)) { + else if ( value instanceof java.util.Date date ) { + final Calendar cal = new GregorianCalendar(); + cal.setTime( date ); + return cal; + } + else { throw unknownWrap( value.getClass() ); } - Calendar cal = new GregorianCalendar(); - cal.setTime( (java.util.Date) value ); - return cal; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaType.java index bd2a9accb4..d480795b7f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaType.java @@ -117,17 +117,17 @@ public class CalendarTimeJavaType extends AbstractTemporalJavaType { if ( value == null ) { return null; } - if (value instanceof Calendar) { - return (Calendar) value; + else if (value instanceof Calendar calendar) { + return calendar; } - - if ( !(value instanceof Date)) { + else if ( value instanceof Date date) { + final Calendar cal = new GregorianCalendar(); + cal.setTime( date ); + return cal; + } + else { throw unknownWrap( value.getClass() ); } - - Calendar cal = new GregorianCalendar(); - cal.setTime( (Date) value ); - return cal; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CharacterArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CharacterArrayJavaType.java index d2e196caca..ecdea5ef9d 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CharacterArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CharacterArrayJavaType.java @@ -45,7 +45,7 @@ public class CharacterArrayJavaType extends AbstractClassJavaType { @Override public boolean areEqual(Character[] one, Character[] another) { return one == another - || ( one != null && another != null && Arrays.equals( one, another ) ); + || one != null && another != null && Arrays.equals( one, another ); } @Override @@ -97,17 +97,17 @@ public class CharacterArrayJavaType extends AbstractClassJavaType { if ( value == null ) { return null; } - if (value instanceof Character[]) { - return (Character[]) value; + if (value instanceof Character[] characters) { + return characters; } - if (value instanceof String) { - return wrapChars( ( (String) value ).toCharArray() ); + if (value instanceof String string) { + return wrapChars( string.toCharArray() ); } - if (value instanceof Clob) { - return wrapChars( DataHelper.extractString( ( (Clob) value ) ).toCharArray() ); + if (value instanceof Clob clob) { + return wrapChars( DataHelper.extractString( clob ).toCharArray() ); } - if (value instanceof Reader) { - return wrapChars( DataHelper.extractString( (Reader) value ).toCharArray() ); + if (value instanceof Reader reader) { + return wrapChars( DataHelper.extractString( reader ).toCharArray() ); } throw unknownWrap( value.getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClobJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClobJavaType.java index d3e8265b4d..a6f043577e 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClobJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClobJavaType.java @@ -145,17 +145,13 @@ public class ClobJavaType extends AbstractClassJavaType { if ( value == null ) { return null; } - - // Support multiple return types from - // org.hibernate.type.descriptor.sql.ClobTypeDescriptor - if ( Clob.class.isAssignableFrom( value.getClass() ) ) { - return options.getLobCreator().wrap( (Clob) value ); + else if ( value instanceof Clob clob ) { + return options.getLobCreator().wrap( clob ); } - else if ( String.class.isAssignableFrom( value.getClass() ) ) { - return options.getLobCreator().createClob( ( String ) value); + else if ( value instanceof String string ) { + return options.getLobCreator().createClob( string ); } - else if ( Reader.class.isAssignableFrom( value.getClass() ) ) { - Reader reader = (Reader) value; + else if ( value instanceof Reader reader ) { return options.getLobCreator().createClob( DataHelper.extractString( reader ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DateJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DateJavaType.java index bae8b2f2b6..e9e005a724 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DateJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DateJavaType.java @@ -151,16 +151,16 @@ public class DateJavaType extends AbstractTemporalJavaType implements Vers if ( value == null ) { return null; } - if (value instanceof Date) { - return (Date) value; + if (value instanceof Date date) { + return date; } - if (value instanceof Long) { - return new Date( (Long) value ); + if (value instanceof Long longValue) { + return new Date( longValue ); } - if (value instanceof Calendar) { - return new Date( ( (Calendar) value ).getTimeInMillis() ); + if (value instanceof Calendar calendar) { + return new Date( calendar.getTimeInMillis() ); } throw unknownWrap( value.getClass() ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleJavaType.java index 68c9f94680..6acab87c10 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleJavaType.java @@ -89,14 +89,14 @@ public class DoubleJavaType extends AbstractClassJavaType implements if ( value == null ) { return null; } - if ( value instanceof Double ) { - return (Double) value; + if ( value instanceof Double doubleValue ) { + return doubleValue; } - if ( value instanceof Number ) { - return ( (Number) value ).doubleValue(); + if ( value instanceof Number number ) { + return number.doubleValue(); } - else if ( value instanceof String ) { - return Double.valueOf( ( (String) value ) ); + else if ( value instanceof String string ) { + return Double.valueOf( string ); } throw unknownWrap( value.getClass() ); } @@ -157,41 +157,29 @@ public class DoubleJavaType extends AbstractClassJavaType implements return null; } - if ( value instanceof Double ) { - return ( (Double) value ); + if ( value instanceof Double doubleValue ) { + return doubleValue; } - if ( value instanceof Byte ) { - return ( (Byte) value ).doubleValue(); + if ( value instanceof Float floatValue ) { + return CoercionHelper.toDouble( floatValue ); } - if ( value instanceof Short ) { - return ( (Short) value ).doubleValue(); + if ( value instanceof BigInteger bigInteger ) { + return CoercionHelper.toDouble( bigInteger ); } - if ( value instanceof Integer ) { - return ( (Integer) value ).doubleValue(); + if ( value instanceof BigDecimal bigDecimal ) { + return CoercionHelper.toDouble( bigDecimal ); } - if ( value instanceof Long ) { - return ( (Long) value ).doubleValue(); + if ( value instanceof Number number ) { + return number.doubleValue(); } - if ( value instanceof Float ) { - return CoercionHelper.toDouble( (Float) value ); - } - - if ( value instanceof BigInteger ) { - return CoercionHelper.toDouble( (BigInteger) value ); - } - - if ( value instanceof BigDecimal ) { - return CoercionHelper.toDouble( (BigDecimal) value ); - } - - if ( value instanceof String ) { + if ( value instanceof String string ) { return CoercionHelper.coerceWrappingError( - () -> Double.parseDouble( (String) value ) + () -> Double.parseDouble( string ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoublePrimitiveArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoublePrimitiveArrayJavaType.java index bbeedcde33..d0e386e39f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoublePrimitiveArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoublePrimitiveArrayJavaType.java @@ -149,16 +149,16 @@ public class DoublePrimitiveArrayJavaType extends AbstractArrayJavaType ) { - final Collection collection = (Collection) value; + else if ( value instanceof Collection collection ) { final double[] wrapped = new double[collection.size()]; int i = 0; for ( Object e : collection ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatJavaType.java index 956af27bc9..ad91f5f234 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatJavaType.java @@ -88,14 +88,14 @@ public class FloatJavaType extends AbstractClassJavaType implements Primi if ( value == null ) { return null; } - if (value instanceof Float) { - return (Float) value; + if (value instanceof Float floatValue) { + return floatValue; } - if (value instanceof Number) { - return ( (Number) value ).floatValue(); + if (value instanceof Number number) { + return number.floatValue(); } - else if (value instanceof String) { - return Float.valueOf( ( (String) value ) ); + else if (value instanceof String string) { + return Float.valueOf( string ); } throw unknownWrap( value.getClass() ); } @@ -154,36 +154,12 @@ public class FloatJavaType extends AbstractClassJavaType implements Primi return null; } - if ( value instanceof Float ) { - return (Float) value; + if ( value instanceof Float floatValue ) { + return floatValue; } - if ( value instanceof Double ) { - return ( (Double) value ).floatValue(); - } - - if ( value instanceof Byte ) { - return ( (Byte) value ).floatValue(); - } - - if ( value instanceof Short ) { - return ( (Short) value ).floatValue(); - } - - if ( value instanceof Integer ) { - return ( (Integer) value ).floatValue(); - } - - if ( value instanceof Long ) { - return ( (Long) value ).floatValue(); - } - - if ( value instanceof BigInteger ) { - return ( (BigInteger) value ).floatValue(); - } - - if ( value instanceof BigDecimal ) { - return ( (BigDecimal) value ).floatValue(); + if ( value instanceof Number number ) { + return number.floatValue(); } if ( value instanceof String ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatPrimitiveArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatPrimitiveArrayJavaType.java index 637210daf2..a212e321bf 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatPrimitiveArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatPrimitiveArrayJavaType.java @@ -149,16 +149,16 @@ public class FloatPrimitiveArrayJavaType extends AbstractArrayJavaType ) { - final Collection collection = (Collection) value; + else if ( value instanceof Collection collection ) { final float[] wrapped = new float[collection.size()]; int i = 0; for ( Object e : collection ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InetAddressJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InetAddressJavaType.java index 0b5397371e..3697dc58b6 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InetAddressJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InetAddressJavaType.java @@ -74,20 +74,20 @@ public class InetAddressJavaType extends AbstractClassJavaType { if ( value == null ) { return null; } - if (value instanceof InetAddress) { - return (InetAddress) value; + if (value instanceof InetAddress inetAddress) { + return inetAddress; } - if (value instanceof byte[]) { + if (value instanceof byte[] bytes) { try { - return InetAddress.getByAddress( (byte[]) value ); + return InetAddress.getByAddress( bytes ); } catch (UnknownHostException e) { throw new IllegalArgumentException( e ); } } - if (value instanceof String) { + if (value instanceof String string) { try { - return InetAddress.getByName( (String) value ); + return InetAddress.getByName( string ); } catch (UnknownHostException e) { throw new IllegalArgumentException( e ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerJavaType.java index ad0634983f..ec0d596957 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerJavaType.java @@ -85,14 +85,14 @@ public class IntegerJavaType extends AbstractClassJavaType if ( value == null ) { return null; } - if (value instanceof Integer) { - return (Integer) value; + if (value instanceof Integer integer) { + return integer; } - if (value instanceof Number) { - return ( (Number) value ).intValue(); + if (value instanceof Number number) { + return number.intValue(); } - if (value instanceof String) { - return Integer.valueOf( (String) value ); + if (value instanceof String string) { + return Integer.valueOf( string ); } throw unknownWrap( value.getClass() ); } @@ -147,41 +147,41 @@ public class IntegerJavaType extends AbstractClassJavaType return null; } - if ( value instanceof Integer ) { - return (int) value; + if ( value instanceof Integer integer ) { + return integer; } - if ( value instanceof Short ) { - return CoercionHelper.toInteger( (short) value ); + if ( value instanceof Short shortValue ) { + return CoercionHelper.toInteger( shortValue ); } - if ( value instanceof Byte ) { - return CoercionHelper.toInteger( (byte) value ); + if ( value instanceof Byte byteValue ) { + return CoercionHelper.toInteger( byteValue ); } - if ( value instanceof Long ) { - return CoercionHelper.toInteger( (long) value ); + if ( value instanceof Long longValue ) { + return CoercionHelper.toInteger( longValue ); } - if ( value instanceof Double ) { - return CoercionHelper.toInteger( (double) value ); + if ( value instanceof Double doubleValue ) { + return CoercionHelper.toInteger( doubleValue ); } - if ( value instanceof Float ) { - return CoercionHelper.toInteger( (float) value ); + if ( value instanceof Float floatValue ) { + return CoercionHelper.toInteger( floatValue ); } - if ( value instanceof BigInteger ) { - return CoercionHelper.toInteger( (BigInteger) value ); + if ( value instanceof BigInteger bigInteger ) { + return CoercionHelper.toInteger( bigInteger ); } - if ( value instanceof BigDecimal ) { - return CoercionHelper.toInteger( (BigDecimal) value ); + if ( value instanceof BigDecimal bigDecimal ) { + return CoercionHelper.toInteger( bigDecimal ); } - if ( value instanceof String ) { + if ( value instanceof String string ) { return CoercionHelper.coerceWrappingError( - () -> Integer.parseInt( (String) value ) + () -> Integer.parseInt( string ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerPrimitiveArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerPrimitiveArrayJavaType.java index f91a30f5a6..ebe30630c0 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerPrimitiveArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerPrimitiveArrayJavaType.java @@ -149,16 +149,16 @@ public class IntegerPrimitiveArrayJavaType extends AbstractArrayJavaType ) { - final Collection collection = (Collection) value; + else if ( value instanceof Collection collection ) { final int[] wrapped = new int[collection.size()]; int i = 0; for ( Object e : collection ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateJavaType.java index d7ed8d21f9..0581cf98dc 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateJavaType.java @@ -187,24 +187,24 @@ public class JdbcDateJavaType extends AbstractTemporalJavaType { return null; } - if ( value instanceof java.sql.Date ) { - return (java.sql.Date) value; + if ( value instanceof java.sql.Date date ) { + return date; } - if ( value instanceof Long ) { - return new java.sql.Date( toDateEpoch( (Long) value ) ); + if ( value instanceof Long longValue ) { + return new java.sql.Date( toDateEpoch( longValue ) ); } - if ( value instanceof Calendar ) { - return new java.sql.Date( toDateEpoch( ( (Calendar) value ).getTimeInMillis() ) ); + if ( value instanceof Calendar calendar ) { + return new java.sql.Date( toDateEpoch( calendar.getTimeInMillis() ) ); } - if ( value instanceof Date ) { - return unwrapSqlDate( (Date) value ); + if ( value instanceof Date date ) { + return unwrapSqlDate( date ); } - if ( value instanceof LocalDate ) { - return java.sql.Date.valueOf( (LocalDate) value ); + if ( value instanceof LocalDate localDate ) { + return java.sql.Date.valueOf( localDate ); } throw unknownWrap( value.getClass() ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeJavaType.java index 7be5319863..6b4e5b0a72 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeJavaType.java @@ -175,16 +175,15 @@ public class JdbcTimeJavaType extends AbstractTemporalJavaType { return null; } - if ( value instanceof Time ) { - return (Date) value; + if ( value instanceof Time time ) { + return time; } - if ( value instanceof Date ) { - return new Time( ( (Date) value ).getTime() % 86_400_000 ); + if ( value instanceof Date date ) { + return new Time( date.getTime() % 86_400_000 ); } - if ( value instanceof LocalTime ) { - final LocalTime localTime = (LocalTime) value; + if ( value instanceof LocalTime localTime ) { final Time time = Time.valueOf( localTime ); if ( localTime.getNano() == 0 ) { return time; @@ -193,12 +192,12 @@ public class JdbcTimeJavaType extends AbstractTemporalJavaType { return new Time( time.getTime() + DateTimeUtils.roundToPrecision( localTime.getNano(), 3 ) / 1000000 ); } - if ( value instanceof Long ) { - return new Time( (Long) value ); + if ( value instanceof Long longValue ) { + return new Time( longValue ); } - if ( value instanceof Calendar ) { - return new Time( ( (Calendar) value ).getTimeInMillis() % 86_400_000 ); + if ( value instanceof Calendar calendar ) { + return new Time( calendar.getTimeInMillis() % 86_400_000 ); } throw unknownWrap( value.getClass() ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java index 2674935b70..1e33d20a46 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java @@ -167,24 +167,24 @@ public class JdbcTimestampJavaType extends AbstractTemporalJavaType implem if ( value == null ) { return null; } - if ( value instanceof Timestamp ) { - return (Timestamp) value; + if ( value instanceof Timestamp timestamp ) { + return timestamp; } - if ( value instanceof Date ) { - return new Timestamp( ( (Date) value ).getTime() ); + if ( value instanceof Date date ) { + return new Timestamp( date.getTime() ); } - if ( value instanceof LocalDateTime ) { - return Timestamp.valueOf( (LocalDateTime) value ); + if ( value instanceof LocalDateTime localDateTime ) { + return Timestamp.valueOf( localDateTime ); } - if ( value instanceof Long ) { - return new Timestamp( (Long) value ); + if ( value instanceof Long longValue ) { + return new Timestamp( longValue ); } - if ( value instanceof Calendar ) { - return new Timestamp( ( (Calendar) value ).getTimeInMillis() ); + if ( value instanceof Calendar calendar ) { + return new Timestamp( calendar.getTimeInMillis() ); } throw unknownWrap( value.getClass() ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java index 13e8fc678e..f78deb0138 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java @@ -107,11 +107,11 @@ public class LocaleJavaType extends AbstractClassJavaType { if ( value == null ) { return null; } - if ( value instanceof Locale ) { - return (Locale) value; + if ( value instanceof Locale locale ) { + return locale; } - if (value instanceof CharSequence) { - return fromString( (CharSequence) value ); + if (value instanceof CharSequence charSequence) { + return fromString( charSequence ); } throw unknownWrap( value.getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongJavaType.java index aeefc8c6d1..e879200567 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongJavaType.java @@ -85,14 +85,14 @@ public class LongJavaType extends AbstractClassJavaType if ( value == null ) { return null; } - if ( value instanceof Long ) { - return (Long) value; + if ( value instanceof Long longValue ) { + return longValue; } - if ( value instanceof Number ) { - return ( (Number) value ).longValue(); + if ( value instanceof Number number ) { + return number.longValue(); } - else if ( value instanceof String ) { - return Long.valueOf( ( (String) value ) ); + else if ( value instanceof String string ) { + return Long.valueOf( string ); } throw unknownWrap( value.getClass() ); } @@ -113,41 +113,41 @@ public class LongJavaType extends AbstractClassJavaType return null; } - if ( value instanceof Long ) { - return ( (Long) value ); + if ( value instanceof Long longValue ) { + return longValue; } - if ( value instanceof Byte ) { - return CoercionHelper.toLong( (Byte) value ); + if ( value instanceof Byte byteValue ) { + return CoercionHelper.toLong( byteValue ); } - if ( value instanceof Short ) { - return CoercionHelper.toLong( (Short) value ); + if ( value instanceof Short shortValue ) { + return CoercionHelper.toLong( shortValue ); } - if ( value instanceof Integer ) { - return CoercionHelper.toLong( (Integer) value ); + if ( value instanceof Integer integerValue ) { + return CoercionHelper.toLong( integerValue ); } - if ( value instanceof Double ) { - return CoercionHelper.toLong( (Double) value ); + if ( value instanceof Double doubleValue ) { + return CoercionHelper.toLong( doubleValue ); } - if ( value instanceof Float ) { - return CoercionHelper.toLong( (Float) value ); + if ( value instanceof Float floatValue ) { + return CoercionHelper.toLong( floatValue ); } - if ( value instanceof BigInteger ) { - return CoercionHelper.toLong( (BigInteger) value ); + if ( value instanceof BigInteger bigInteger ) { + return CoercionHelper.toLong( bigInteger ); } - if ( value instanceof BigDecimal ) { - return CoercionHelper.toLong( (BigDecimal) value ); + if ( value instanceof BigDecimal bigDecimal ) { + return CoercionHelper.toLong( bigDecimal ); } - if ( value instanceof String ) { + if ( value instanceof String string ) { return CoercionHelper.coerceWrappingError( - () -> Long.parseLong( (String) value ) + () -> Long.parseLong( string ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongPrimitiveArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongPrimitiveArrayJavaType.java index 7a28cc69d6..85a9b210cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongPrimitiveArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongPrimitiveArrayJavaType.java @@ -149,16 +149,16 @@ public class LongPrimitiveArrayJavaType extends AbstractArrayJavaType ) { - final Collection collection = (Collection) value; + else if ( value instanceof Collection collection ) { final long[] wrapped = new long[collection.size()]; int i = 0; for ( Object e : collection ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/NClobJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/NClobJavaType.java index 3790688ef7..d5f5b9a0ca 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/NClobJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/NClobJavaType.java @@ -113,8 +113,8 @@ public class NClobJavaType extends AbstractClassJavaType { } private NClob getOrCreateNClob(NClob value, WrapperOptions options) throws SQLException { - if ( value instanceof WrappedNClob ) { - value = ( (WrappedNClob) value ).getWrappedNClob(); + if ( value instanceof WrappedNClob wrappedNClob ) { + value = wrappedNClob.getWrappedNClob(); } if ( options.getDialect().useConnectionToCreateLob() ) { if ( value.length() == 0 ) { @@ -137,11 +137,10 @@ public class NClobJavaType extends AbstractClassJavaType { // Support multiple return types from // org.hibernate.type.descriptor.sql.ClobTypeDescriptor - if ( NClob.class.isAssignableFrom( value.getClass() ) ) { - return options.getLobCreator().wrap( (NClob) value ); + if ( value instanceof NClob clob ) { + return options.getLobCreator().wrap( clob ); } - else if ( Reader.class.isAssignableFrom( value.getClass() ) ) { - Reader reader = (Reader) value; + else if ( value instanceof Reader reader ) { return options.getLobCreator().createNClob( DataHelper.extractString( reader ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ObjectArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ObjectArrayJavaType.java index 66fc0527ae..59ea428d00 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ObjectArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ObjectArrayJavaType.java @@ -89,8 +89,8 @@ public class ObjectArrayJavaType extends AbstractClassJavaType { if ( value == null ) { return null; } - if (value instanceof Object[]) { - return (Object[]) value; + if (value instanceof Object[] objects) { + return objects; } throw unknownWrap( value.getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveByteArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveByteArrayJavaType.java index e62159b47e..9d99a39b19 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveByteArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveByteArrayJavaType.java @@ -36,7 +36,7 @@ public class PrimitiveByteArrayJavaType extends AbstractClassJavaType @Override public boolean areEqual(byte[] one, byte[] another) { return one == another - || ( one != null && another != null && Arrays.equals( one, another ) ); + || one != null && another != null && Arrays.equals( one, another ); } @Override @@ -134,9 +134,9 @@ public class PrimitiveByteArrayJavaType extends AbstractClassJavaType throw new HibernateException( "Unable to access lob stream", e ); } } - else if ( value instanceof Byte ) { + else if ( value instanceof Byte byteValue ) { // Support binding a single element as parameter value - return new byte[]{ (byte) value }; + return new byte[]{ byteValue }; } throw unknownWrap( value.getClass() ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveCharacterArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveCharacterArrayJavaType.java index 2bb97fabce..f44d1aab30 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveCharacterArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveCharacterArrayJavaType.java @@ -38,7 +38,7 @@ public class PrimitiveCharacterArrayJavaType extends AbstractClassJavaType if ( value == null ) { return null; } - if (value instanceof Short) { - return (Short) value; + if (value instanceof Short shortValue) { + return shortValue; } - if (value instanceof Number) { - return ( (Number) value ).shortValue(); + if (value instanceof Number number) { + return number.shortValue(); } - if (value instanceof String) { - return Short.valueOf( ( (String) value ) ); + if (value instanceof String string) { + return Short.valueOf( string ); } throw unknownWrap( value.getClass() ); } @@ -139,41 +139,41 @@ public class ShortJavaType extends AbstractClassJavaType return null; } - if ( value instanceof Short ) { - return (short) value; + if ( value instanceof Short shortValue ) { + return shortValue; } - if ( value instanceof Byte ) { - return CoercionHelper.toShort( (Byte) value ); + if ( value instanceof Byte byteValue ) { + return CoercionHelper.toShort( byteValue ); } - if ( value instanceof Integer ) { - return CoercionHelper.toShort( (Integer) value ); + if ( value instanceof Integer integerValue ) { + return CoercionHelper.toShort( integerValue ); } - if ( value instanceof Long ) { - return CoercionHelper.toShort( (Long) value ); + if ( value instanceof Long longValue ) { + return CoercionHelper.toShort( longValue ); } - if ( value instanceof Double ) { - return CoercionHelper.toShort( (Double) value ); + if ( value instanceof Double doubleValue ) { + return CoercionHelper.toShort( doubleValue ); } - if ( value instanceof Float ) { - return CoercionHelper.toShort( (Float) value ); + if ( value instanceof Float floatValue ) { + return CoercionHelper.toShort( floatValue ); } - if ( value instanceof BigInteger ) { - return CoercionHelper.toShort( (BigInteger) value ); + if ( value instanceof BigInteger bigInteger ) { + return CoercionHelper.toShort( bigInteger ); } - if ( value instanceof BigDecimal ) { - return CoercionHelper.toShort( (BigDecimal) value ); + if ( value instanceof BigDecimal bigDecimal ) { + return CoercionHelper.toShort( bigDecimal ); } - if ( value instanceof String ) { + if ( value instanceof String string ) { return CoercionHelper.coerceWrappingError( - () -> Short.parseShort( (String) value ) + () -> Short.parseShort( string ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortPrimitiveArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortPrimitiveArrayJavaType.java index ab2fa7336a..77fa1b3e47 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortPrimitiveArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortPrimitiveArrayJavaType.java @@ -149,16 +149,16 @@ public class ShortPrimitiveArrayJavaType extends AbstractArrayJavaType ) { - final Collection collection = (Collection) value; + else if ( value instanceof Collection collection ) { final short[] wrapped = new short[collection.size()]; int i = 0; for ( Object e : collection ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UrlJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UrlJavaType.java index 51212067ff..8dde846744 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UrlJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UrlJavaType.java @@ -7,7 +7,6 @@ package org.hibernate.type.descriptor.java; import java.net.MalformedURLException; import java.net.URL; -import org.hibernate.HibernateException; import org.hibernate.type.SqlTypes; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -44,7 +43,7 @@ public class UrlJavaType extends AbstractClassJavaType { return new URL( string.toString() ); } catch ( MalformedURLException e ) { - throw new HibernateException( "Unable to convert string [" + string + "] to URL : " + e ); + throw new CoercionException( "Unable to convert string [" + string + "] to URL : " + e ); } }