Skip to content

Commit 56e2d4b

Browse files
committed
lots of safe type casts through whole code base
1 parent 8f654f0 commit 56e2d4b

File tree

277 files changed

+1642
-1834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

277 files changed

+1642
-1834
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/AltibaseSqlAstTranslator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ protected void renderComparison(Expression lhs, ComparisonOperator operator, Exp
6464
@Override
6565
public void visitOver(Over<?> over) {
6666
final Expression expression = over.getExpression();
67-
if ( expression instanceof FunctionExpression && "row_number".equals( ( (FunctionExpression) expression ).getFunctionName() ) ) {
67+
if ( expression instanceof FunctionExpression functionExpression
68+
&& "row_number".equals( functionExpression.getFunctionName() ) ) {
6869
if ( over.getPartitions().isEmpty() && over.getOrderList().isEmpty()
6970
&& over.getStartKind() == FrameKind.UNBOUNDED_PRECEDING
7071
&& over.getEndKind() == FrameKind.CURRENT_ROW

hibernate-core/src/main/java/org/hibernate/ConnectionAcquisitionMode.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,13 @@ public static ConnectionAcquisitionMode interpret(Object setting) {
4040
if ( setting == null ) {
4141
return null;
4242
}
43-
44-
if ( setting instanceof ConnectionAcquisitionMode mode ) {
43+
else if ( setting instanceof ConnectionAcquisitionMode mode ) {
4544
return mode;
4645
}
47-
48-
final String value = setting.toString();
49-
if ( isEmpty( value ) ) {
50-
return null;
46+
else {
47+
final String value = setting.toString();
48+
return isEmpty( value ) ? null : interpret( value );
5149
}
5250

53-
return interpret( value );
5451
}
5552
}

hibernate-core/src/main/java/org/hibernate/ConnectionReleaseMode.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@ public static ConnectionReleaseMode interpret(Object setting) {
7171
if ( setting == null ) {
7272
return null;
7373
}
74-
75-
if ( setting instanceof ConnectionReleaseMode mode ) {
74+
else if ( setting instanceof ConnectionReleaseMode mode ) {
7675
return mode;
7776
}
78-
79-
final String value = setting.toString();
80-
if ( isEmpty( value ) ) {
81-
return null;
77+
else {
78+
final String value = setting.toString();
79+
if ( isEmpty( value ) ) {
80+
return null;
81+
}
82+
// here we disregard "auto"
83+
else if ( value.equalsIgnoreCase( "auto" ) ) {
84+
return null;
85+
}
86+
else {
87+
return parse( value );
88+
}
8289
}
83-
84-
// here we disregard "auto"
85-
if ( value.equalsIgnoreCase( "auto" ) ) {
86-
return null;
87-
}
88-
89-
return parse( value );
9090
}
9191
}

hibernate-core/src/main/java/org/hibernate/Hibernate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
* delegate.
6666
* <li>The proxy does not have the same concrete type as the proxied delegate, and so
6767
* {@link #getClass(Object)} must be used in place of {@link Object#getClass()},
68-
* and this method fetches the entity by side-effect.
68+
* and this method fetches the entity by side effect.
6969
* <li>For a polymorphic association, the concrete type of the associated entity is
7070
* not known until the delegate is fetched from the database, and so
7171
* {@link #unproxy(Object, Class)}} must be used to perform typecasts, and

hibernate-core/src/main/java/org/hibernate/PropertySetterAccessException.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ public PropertySetterAccessException(
5151
}
5252

5353
public static String loggablePropertyValueString(Object value) {
54-
if ( value instanceof Collection || value instanceof HibernateProxy ) {
55-
return value.getClass().getSimpleName();
56-
}
57-
return value.toString();
54+
return value instanceof Collection || value instanceof HibernateProxy
55+
? value.getClass().getSimpleName()
56+
: value.toString();
5857
}
5958

6059
@Override

hibernate-core/src/main/java/org/hibernate/action/internal/AbstractEntityInsertAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ else if ( attribute.isEmbeddedAttributeMapping() ) {
211211

212212
private void addCollectionKey(
213213
PluralAttributeMapping pluralAttributeMapping,
214-
Object o,
214+
Object object,
215215
PersistenceContext persistenceContext) {
216-
if ( o instanceof PersistentCollection ) {
216+
if ( object instanceof PersistentCollection ) {
217217
final CollectionPersister collectionPersister = pluralAttributeMapping.getCollectionDescriptor();
218218
final Object key = AbstractEntityPersister.getCollectionKey(
219219
collectionPersister,
@@ -223,7 +223,7 @@ private void addCollectionKey(
223223
);
224224
if ( key != null ) {
225225
final CollectionKey collectionKey = new CollectionKey( collectionPersister, key );
226-
persistenceContext.addCollectionByKey( collectionKey, (PersistentCollection<?>) o );
226+
persistenceContext.addCollectionByKey( collectionKey, (PersistentCollection<?>) object );
227227
}
228228
}
229229
}

hibernate-core/src/main/java/org/hibernate/action/internal/EntityDeleteAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ protected void postCommitDelete(boolean success) {
234234
}
235235

236236
private static void postCommitDeleteOnUnsuccessful(PostDeleteEventListener listener, PostDeleteEvent event) {
237-
if ( listener instanceof PostCommitDeleteEventListener ) {
238-
( (PostCommitDeleteEventListener) listener ).onPostDeleteCommitFailed( event );
237+
if ( listener instanceof PostCommitDeleteEventListener postCommitDeleteEventListener ) {
238+
postCommitDeleteEventListener.onPostDeleteCommitFailed( event );
239239
}
240240
else {
241241
//default to the legacy implementation that always fires the event

hibernate-core/src/main/java/org/hibernate/action/internal/EntityUpdateAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ protected void postCommitUpdate(boolean success) {
383383
}
384384

385385
private void onPostCommitFailure(PostUpdateEventListener listener, PostUpdateEvent event) {
386-
if ( listener instanceof PostCommitUpdateEventListener ) {
387-
((PostCommitUpdateEventListener) listener).onPostUpdateCommitFailed( event );
386+
if ( listener instanceof PostCommitUpdateEventListener postCommitUpdateEventListener ) {
387+
postCommitUpdateEventListener.onPostUpdateCommitFailed( event );
388388
}
389389
else {
390390
//default to the legacy implementation that always fires the event

hibernate-core/src/main/java/org/hibernate/annotations/OnDeleteAction.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,25 @@ public static OnDeleteAction fromExternalForm(Object value) {
6363
if ( value == null ) {
6464
return null;
6565
}
66-
67-
if ( value instanceof OnDeleteAction onDeleteAction ) {
66+
else if ( value instanceof OnDeleteAction onDeleteAction ) {
6867
return onDeleteAction;
6968
}
69+
else {
70+
final String valueString = value.toString();
71+
try {
72+
return valueOf( valueString );
73+
}
74+
catch (IllegalArgumentException e) {
75+
// the name did not match the enum value name...
76+
}
7077

71-
final String valueString = value.toString();
72-
try {
73-
return valueOf( valueString );
74-
}
75-
catch (IllegalArgumentException e) {
76-
// the name did not match the enum value name...
77-
}
78-
79-
for ( OnDeleteAction checkAction : values() ) {
80-
if ( checkAction.getAlternativeName().equalsIgnoreCase( valueString ) ) {
81-
return checkAction;
78+
for ( OnDeleteAction checkAction : values() ) {
79+
if ( checkAction.getAlternativeName().equalsIgnoreCase( valueString ) ) {
80+
return checkAction;
81+
}
8282
}
83-
}
8483

85-
return null;
84+
return null;
85+
}
8686
}
8787
}

hibernate-core/src/main/java/org/hibernate/binder/internal/CommentBinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void bind(Comment comment, MetadataBuildingContext context, PersistentCla
3535
+ "' was annotated '@Comment'");
3636
}
3737
else if ( value instanceof Collection collection ) {
38-
Table table = collection.getCollectionTable();
38+
final Table table = collection.getCollectionTable();
3939
// by default, the comment goes on the table
4040
if ( on.isEmpty() || table.getName().equalsIgnoreCase( on ) ) {
4141
table.setComment( text );

0 commit comments

Comments
 (0)