Skip to content

Commit 9b55695

Browse files
chore: clearer error message when flat record NPEs bc the schema is not found (#758)
1 parent a1b1a00 commit 9b55695

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

hollow/src/main/java/com/netflix/hollow/core/write/objectmapper/flatrecords/FlatRecordExtractor.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,22 @@ public synchronized FlatRecord extract(String type, int ordinal) {
5757

5858
HollowTypeReadState typeState = extractFrom.getTypeState(type);
5959

60-
extractHollowRecord(typeState, ordinal);
60+
extractHollowRecord(type, typeState, ordinal);
6161

6262
return writer.generateFlatRecord();
6363
}
6464

65-
private void extractHollowRecord(HollowTypeReadState typeState, int ordinal) {
66-
if(ordinal == -1)
65+
private void extractHollowRecord(String type, HollowTypeReadState typeState, int ordinal) {
66+
if (ordinal == -1) {
6767
return;
68+
}
69+
70+
if (typeState == null) {
71+
throw new IllegalArgumentException("Type '" + type + "' not found in HollowReadStateEngine");
72+
}
6873

6974
traverse(typeState, ordinal);
7075

71-
String type = typeState.getSchema().getName();
72-
7376
HollowRecordCopier recordCopier = recordCopier(type);
7477
HollowWriteRecord rec = recordCopier.copy(ordinal);
7578

@@ -100,9 +103,10 @@ private void traverseObject(HollowObjectTypeReadState typeState, int ordinal) {
100103

101104
for(int i=0;i<schema.numFields();i++) {
102105
if(schema.getFieldType(i) == FieldType.REFERENCE) {
106+
String refType = schema.getReferencedType(i);;
103107
HollowTypeReadState refTypeState = schema.getReferencedTypeState(i);
104108
int refOrdinal = typeState.readOrdinal(ordinal, i);
105-
extractHollowRecord(refTypeState, refOrdinal);
109+
extractHollowRecord(refType, refTypeState, refOrdinal);
106110
}
107111
}
108112
}
@@ -115,7 +119,7 @@ private void traverseList(HollowListTypeReadState typeState, int ordinal) {
115119
for(int i=0;i<size;i++) {
116120
int refOrdinal = typeState.getElementOrdinal(ordinal, i);
117121
if(refOrdinal != HollowConstants.ORDINAL_NONE)
118-
extractHollowRecord(schema.getElementTypeState(), refOrdinal);
122+
extractHollowRecord(schema.getElementType(), schema.getElementTypeState(), refOrdinal);
119123
}
120124
}
121125

@@ -127,7 +131,7 @@ private void traverseSet(HollowSetTypeReadState typeState, int ordinal) {
127131
int refOrdinal = iter.next();
128132
while(refOrdinal != HollowOrdinalIterator.NO_MORE_ORDINALS) {
129133
if(refOrdinal != HollowConstants.ORDINAL_NONE)
130-
extractHollowRecord(schema.getElementTypeState(), refOrdinal);
134+
extractHollowRecord(schema.getElementType(), schema.getElementTypeState(), refOrdinal);
131135
refOrdinal = iter.next();
132136
}
133137
}
@@ -139,9 +143,9 @@ private void traverseMap(HollowMapTypeReadState typeState, int ordinal) {
139143

140144
while(iter.next()) {
141145
if(iter.getKey() != HollowConstants.ORDINAL_NONE)
142-
extractHollowRecord(schema.getKeyTypeState(), iter.getKey());
146+
extractHollowRecord(schema.getKeyType(), schema.getKeyTypeState(), iter.getKey());
143147
if(iter.getValue() != HollowConstants.ORDINAL_NONE)
144-
extractHollowRecord(schema.getValueTypeState(), iter.getValue());
148+
extractHollowRecord(schema.getValueType(), schema.getValueTypeState(), iter.getValue());
145149
}
146150
}
147151

0 commit comments

Comments
 (0)