From 56c2f6b3f95ff603de705fd4ebc65c5ac55b983c Mon Sep 17 00:00:00 2001 From: Abhilash Mandaliya Date: Wed, 12 May 2021 16:50:18 +0530 Subject: [PATCH] cleaned some code in GenericJsonRecord (#10527) (cherry picked from commit 24b0d064e377dedda2049f6177028f4c26a870bf) --- .../schema/generic/GenericJsonRecord.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericJsonRecord.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericJsonRecord.java index 7b4a530fec5a7..eaefaa570fd4a 100644 --- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericJsonRecord.java +++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericJsonRecord.java @@ -98,29 +98,29 @@ public Object getField(String fieldName) { } private boolean isBinaryValue(String fieldName) { - boolean isBinary = false; + if (schemaInfo == null) { + return false; + } - do { - if (schemaInfo == null) { - break; + boolean isBinary = false; + try { + org.apache.avro.Schema schema = parseAvroSchema(schemaInfo.getSchemaDefinition()); + org.apache.avro.Schema.Field field = schema.getField(fieldName); + if (field == null) { + return false; } - - try { - org.apache.avro.Schema schema = parseAvroSchema(schemaInfo.getSchemaDefinition()); - org.apache.avro.Schema.Field field = schema.getField(fieldName); - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode jsonNode = objectMapper.readTree(field.schema().toString()); - for (JsonNode node : jsonNode) { - JsonNode jn = node.get("type"); - if (jn != null && ("bytes".equals(jn.asText()) || "byte".equals(jn.asText()))) { - isBinary = true; - } + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = objectMapper.readTree(field.schema().toString()); + for (JsonNode node : jsonNode) { + JsonNode jn = node.get("type"); + if (jn != null && ("bytes".equals(jn.asText()) || "byte".equals(jn.asText()))) { + isBinary = true; + break; } - } catch (Exception e) { - log.error("parse schemaInfo failed. ", e); } - } while (false); - + } catch (Exception e) { + log.error("parse schemaInfo failed. ", e); + } return isBinary; }