@@ -543,12 +543,16 @@ private RegisterSchemaResponse registerWithResponse(
543543 ? registerAndGetId (subject , schema , version , id , normalize , propagateSchemaTags )
544544 : registerAndGetId (subject , schema , normalize , propagateSchemaTags );
545545 schemaResponseMap .put (schema , retrievedResponse );
546- String context = toQualifiedContext (subject );
547- final Cache <Integer , ParsedSchema > idSchemaMap = idToSchemaCache .get (
548- context , () -> CacheBuilder .newBuilder ()
549- .maximumSize (cacheCapacity )
550- .build ());
551- idSchemaMap .put (retrievedResponse .getId (), schema );
546+ if (retrievedResponse .getSchema () != null ) {
547+ String context = toQualifiedContext (subject );
548+ final Cache <Integer , ParsedSchema > idSchemaMap = idToSchemaCache .get (
549+ context , () -> CacheBuilder .newBuilder ()
550+ .maximumSize (cacheCapacity )
551+ .build ());
552+ ParsedSchema retrievedSchema =
553+ parseSchemaOrElseThrow (new Schema (null , retrievedResponse ));
554+ idSchemaMap .put (retrievedResponse .getId (), retrievedSchema );
555+ }
552556 return retrievedResponse ;
553557 }
554558 } catch (ExecutionException e ) {
@@ -826,14 +830,20 @@ public int getId(String subject, ParsedSchema schema, boolean normalize)
826830 return cachedId ;
827831 }
828832
829- final int retrievedId = getIdFromRegistry (subject , schema , normalize );
833+ final RegisterSchemaResponse retrievedResponse =
834+ getIdWithResponseFromRegistry (subject , schema , normalize , false );
835+ final int retrievedId = retrievedResponse .getId ();
830836 schemaIdMap .put (schema , retrievedId );
831- String context = toQualifiedContext (subject );
832- final Cache <Integer , ParsedSchema > idSchemaMap = idToSchemaCache .get (
833- context , () -> CacheBuilder .newBuilder ()
834- .maximumSize (cacheCapacity )
835- .build ());
836- idSchemaMap .put (retrievedId , schema );
837+ if (retrievedResponse .getSchema () != null ) {
838+ String context = toQualifiedContext (subject );
839+ final Cache <Integer , ParsedSchema > idSchemaMap = idToSchemaCache .get (
840+ context , () -> CacheBuilder .newBuilder ()
841+ .maximumSize (cacheCapacity )
842+ .build ());
843+ ParsedSchema retrievedSchema =
844+ parseSchemaOrElseThrow (new Schema (null , retrievedResponse ));
845+ idSchemaMap .put (retrievedId , retrievedSchema );
846+ }
837847 return retrievedId ;
838848 }
839849 } catch (ExecutionException e ) {
@@ -908,12 +918,16 @@ public RegisterSchemaResponse getIdWithResponse(
908918 final RegisterSchemaResponse retrievedResponse =
909919 getIdWithResponseFromRegistry (subject , schema , normalize , false );
910920 schemaResponseMap .put (schema , retrievedResponse );
911- String context = toQualifiedContext (subject );
912- final Cache <Integer , ParsedSchema > idSchemaMap = idToSchemaCache .get (
913- context , () -> CacheBuilder .newBuilder ()
914- .maximumSize (cacheCapacity )
915- .build ());
916- idSchemaMap .put (retrievedResponse .getId (), schema );
921+ if (retrievedResponse .getSchema () != null ) {
922+ String context = toQualifiedContext (subject );
923+ final Cache <Integer , ParsedSchema > idSchemaMap = idToSchemaCache .get (
924+ context , () -> CacheBuilder .newBuilder ()
925+ .maximumSize (cacheCapacity )
926+ .build ());
927+ ParsedSchema retrievedSchema =
928+ parseSchemaOrElseThrow (new Schema (null , retrievedResponse ));
929+ idSchemaMap .put (retrievedResponse .getId (), retrievedSchema );
930+ }
917931 return retrievedResponse ;
918932 }
919933 } catch (ExecutionException e ) {
0 commit comments