private void nullify ( Object target , Field field ) { Class < ? > type = field . getType ( ) ; if ( ! nulls . containsKey ( type ) ) { nulls . put ( type , objenesis . newInstance ( registrar . resolve ( field ) . getType ( ) ) ) ; } try { field . set ( target , nulls . get ( type ) ) ; } catch ( IllegalArgumentException | IllegalAccessException e ) { throw new IrohException ( e ) ; } }
Implements lazy injection by filling in a local null instance of the type required by the field . The original idea was to just define a new location of null itself but Java didn t like that very much so now Iroh will generate a reference for every type it encounters to act as the null for fields of that particular type .