Skip to content

Commit 9a98976

Browse files
committed
don't use NPE to indicate that a PostInitCallbackEntry is unready and needs to be re-queued
because: - to anyone stepping through the code it looks like a bug - nobody *reading* the code would have any way of guessing that this is behavior that can happen, much less that it's expected and correct
1 parent 6fcbe5f commit 9a98976

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import java.io.Serializable;
1010
import java.util.ArrayList;
11-
import java.util.Iterator;
1211
import java.util.List;
1312
import java.util.Locale;
1413
import java.util.function.Consumer;
@@ -595,22 +594,22 @@ public void visitFetchables(Consumer<Fetchable> fetchableConsumer, EntityMapping
595594

596595
@Override
597596
public SelectableMapping getSelectable(int columnIndex) {
598-
return selectableMappings.getSelectable( columnIndex );
597+
return getSelectableMappings().getSelectable( columnIndex );
599598
}
600599

601600
@Override
602601
public int getJdbcTypeCount() {
603-
return selectableMappings.getJdbcTypeCount();
602+
return getSelectableMappings().getJdbcTypeCount();
604603
}
605604

606605
@Override
607606
public List<JdbcMapping> getJdbcMappings() {
608-
return selectableMappings.getJdbcMappings();
607+
return getSelectableMappings().getJdbcMappings();
609608
}
610609

611610
@Override
612611
public int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> action) {
613-
return selectableMappings.forEachSelectable(
612+
return getSelectableMappings().forEachSelectable(
614613
offset,
615614
(index, selectable) -> action.accept( index, selectable.getJdbcMapping() )
616615
);
@@ -690,12 +689,24 @@ public int forEachDisassembledJdbcValue(
690689

691690
@Override
692691
public int forEachSelectable(SelectableConsumer consumer) {
693-
return selectableMappings.forEachSelectable( 0, consumer );
692+
return getSelectableMappings().forEachSelectable( 0, consumer );
694693
}
695694

696695
@Override
697696
public int forEachSelectable(int offset, SelectableConsumer consumer) {
698-
return selectableMappings.forEachSelectable( offset, consumer );
697+
return getSelectableMappings().forEachSelectable( offset, consumer );
698+
}
699+
700+
private SelectableMappings getSelectableMappings() {
701+
if (selectableMappings == null) {
702+
// This is expected to happen when processing a
703+
// PostInitCallbackEntry because the callbacks
704+
// are not ordered. The exception is caught in
705+
// MappingModelCreationProcess.executePostInitCallbacks()
706+
// and the callback is re-queued.
707+
throw new IllegalStateException("not yet ready");
708+
}
709+
return selectableMappings;
699710
}
700711

701712
@Override

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationProcess.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import java.util.ArrayList;
1010
import java.util.HashMap;
11-
import java.util.Iterator;
1211
import java.util.List;
1312
import java.util.Map;
1413

0 commit comments

Comments
 (0)