github-code-scanning[bot] commented on code in PR #1723:
URL: https://github.com/apache/avro/pull/1723#discussion_r1062387630


##########
lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericDatumReader.java:
##########
@@ -117,4 +138,115 @@
       }
     }
   }
+
+  @ParameterizedTest
+  @ValueSource(strings = { "true", "false" })
+  public void simple(String fastReaderProp) throws IOException {
+    final String current = System.getProperty(GenericData.FAST_READER_PROP);
+    try {
+      System.setProperty(GenericData.FAST_READER_PROP, fastReaderProp);
+      Schema schema = Schema.createRecord("Person", "doc", "foo", false,
+          Arrays.asList(new Schema.Field("lastname", 
Schema.create(Schema.Type.STRING), "doc", "Bond")));
+
+      String data = "{}";
+      byte[] toAvro = this.convertJsonToAvro(data.getBytes(), schema);
+
+      final IndexedRecord record = this.readOneRecord(schema, toAvro);
+      Assertions.assertEquals("Bond", 
record.get(schema.getField("lastname").pos()).toString());
+    } finally {
+      if (current == null) {
+        System.clearProperty(GenericData.FAST_READER_PROP);
+      } else {
+        System.setProperty(GenericData.FAST_READER_PROP, current);
+      }
+    }
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = { "true", "false" })
+  void wrong(String fastReaderProp) {
+    final String current = System.getProperty(GenericData.FAST_READER_PROP);
+    try {
+      System.setProperty(GenericData.FAST_READER_PROP, fastReaderProp);
+      Schema schema = Schema.createRecord("Person", "doc", "foo", false,
+          Arrays.asList(new Schema.Field("lastname", 
Schema.create(Schema.Type.STRING), "doc", "last")));
+
+      String data = "{ \"lastname\": 123 }";
+      AvroTypeException exception = 
Assertions.assertThrows(AvroTypeException.class,
+          () -> this.convertJsonToAvro(data.getBytes(), schema));

Review Comment:
   ## Unread local variable
   
   Variable 'AvroTypeException exception' is never read.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/2961)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to