@@ -453,6 +453,17 @@ public StructureModifier<TField> writeDefaults() throws FieldAccessException {
453
453
*/
454
454
@ SuppressWarnings ("unchecked" )
455
455
public <T > StructureModifier <T > withType (Class fieldType , EquivalentConverter <T > converter ) {
456
+ if (fieldType == null ) {
457
+ // It's not supported in this version, so return an empty modifier
458
+ return new StructureModifier <T >() {
459
+ @ Override
460
+ public T read (int index ) { return null ; }
461
+
462
+ @ Override
463
+ public StructureModifier <T > write (int index , T value ) { return this ; }
464
+ };
465
+ }
466
+
456
467
StructureModifier <T > result = subtypeCache .get (fieldType );
457
468
458
469
// Do we need to update the cache?
@@ -462,7 +473,7 @@ public <T> StructureModifier<T> withType(Class fieldType, EquivalentConverter<T>
462
473
int index = 0 ;
463
474
464
475
for (Field field : data ) {
465
- if (fieldType != null && fieldType .isAssignableFrom (field .getType ())) {
476
+ if (fieldType .isAssignableFrom (field .getType ())) {
466
477
filtered .add (field );
467
478
468
479
// Don't use the original index
@@ -476,14 +487,12 @@ public <T> StructureModifier<T> withType(Class fieldType, EquivalentConverter<T>
476
487
477
488
// Cache structure modifiers
478
489
result = withFieldType (fieldType , filtered , defaults );
479
-
480
- if (fieldType != null ) {
481
- subtypeCache .put (fieldType , result );
490
+
491
+ subtypeCache .put (fieldType , result );
482
492
483
- // Automatically compile the structure modifier
484
- if (useStructureCompiler && BackgroundCompiler .getInstance () != null )
485
- BackgroundCompiler .getInstance ().scheduleCompilation (subtypeCache , fieldType );
486
- }
493
+ // Automatically compile the structure modifier
494
+ if (useStructureCompiler && BackgroundCompiler .getInstance () != null )
495
+ BackgroundCompiler .getInstance ().scheduleCompilation (subtypeCache , fieldType );
487
496
}
488
497
489
498
// Add the target too
0 commit comments