Skip to content

Commit 08cf372

Browse files
committed
fix unchecked typecast
1 parent 8f90d00 commit 08cf372

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

  • hibernate-core/src/main/java/org/hibernate/graph/internal

‎hibernate-core/src/main/java/org/hibernate/graph/internal/GraphImpl.java‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
import java.util.HashMap;
2727
import java.util.List;
2828
import java.util.Map;
29-
import java.util.stream.Collectors;
3029

3130
import static java.util.Collections.emptyList;
3231
import static java.util.Collections.emptyMap;
3332
import static java.util.Collections.unmodifiableMap;
33+
import static java.util.stream.Collectors.toMap;
34+
import static java.util.stream.Collectors.toUnmodifiableList;
3435

3536
/**
3637
* Base class for {@link RootGraph} and {@link SubGraph} implementations.
@@ -69,8 +70,15 @@ public final ManagedDomainType<J> getGraphedType() {
6970
}
7071
@Override
7172
public List<jakarta.persistence.AttributeNode<?>> getAttributeNodes() {
72-
//noinspection unchecked,rawtypes
73-
return (List) getAttributeNodeList();
73+
if ( attributeNodes == null ) {
74+
return emptyList();
75+
}
76+
else {
77+
// we need to filter out removed nodes
78+
return attributeNodes.values().stream()
79+
.filter( (node) -> !node.isRemoved() )
80+
.collect( toUnmodifiableList());
81+
}
7482
}
7583

7684

@@ -81,7 +89,9 @@ public List<AttributeNodeImplementor<?,?,?>> getAttributeNodeList() {
8189
}
8290
else {
8391
// we need to filter out removed nodes
84-
return attributeNodes.values().stream().filter( (node) -> !node.isRemoved() ).toList();
92+
return attributeNodes.values().stream()
93+
.filter( (node) -> !node.isRemoved() )
94+
.toList();
8595
}
8696
}
8797

@@ -95,7 +105,7 @@ public List<AttributeNodeImplementor<?,?,?>> getAttributeNodeList() {
95105
.entrySet()
96106
.stream()
97107
.filter( (entry) -> !entry.getValue().isRemoved() )
98-
.collect( Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue ) );
108+
.collect( toMap( Map.Entry::getKey, Map.Entry::getValue ) );
99109
}
100110
}
101111

0 commit comments

Comments
 (0)