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