瀏覽代碼

Fix NPE on producing a message (#1342)

Roman Zabaluev 3 年之前
父節點
當前提交
24f7e4c190

+ 4 - 5
kafka-ui-api/src/main/java/com/provectus/kafka/ui/serde/schemaregistry/SchemaRegistryAwareRecordSerDe.java

@@ -62,14 +62,12 @@ public class SchemaRegistryAwareRecordSerDe implements RecordSerDe {
   @Nullable
   private final JsonSchemaMessageFormatter jsonSchemaMessageFormatter;
 
-  private ObjectMapper objectMapper;
+  private final ObjectMapper objectMapper;
 
-  private SchemaRegistryClient createSchemaRegistryClient(KafkaCluster cluster,
-                                                          ObjectMapper objectMapper) {
+  private SchemaRegistryClient createSchemaRegistryClient(KafkaCluster cluster) {
     if (cluster.getSchemaRegistry() == null) {
       throw new ValidationException("schemaRegistry is not specified");
     }
-    this.objectMapper = objectMapper;
 
     List<SchemaProvider> schemaProviders =
         List.of(new AvroSchemaProvider(), new ProtobufSchemaProvider(), new JsonSchemaProvider());
@@ -98,8 +96,9 @@ public class SchemaRegistryAwareRecordSerDe implements RecordSerDe {
 
   public SchemaRegistryAwareRecordSerDe(KafkaCluster cluster, ObjectMapper objectMapper) {
     this.cluster = cluster;
+    this.objectMapper = objectMapper;
     this.schemaRegistryClient = cluster.getSchemaRegistry() != null
-        ? createSchemaRegistryClient(cluster, objectMapper)
+        ? createSchemaRegistryClient(cluster)
         : null;
     if (schemaRegistryClient != null) {
       this.avroFormatter = new AvroMessageFormatter(schemaRegistryClient);