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


##########
lang/java/avro/src/test/java/org/apache/avro/TestDataFileReader.java:
##########
@@ -212,23 +213,27 @@
     }
   }
 
-  @Test(expected = InvalidAvroMagicException.class)
-  public void testInvalidMagicLength() throws IOException {
-    File f = Files.createTempFile("testInvalidMagicLength", ".avro").toFile();
-    try (FileWriter w = new FileWriter(f)) {
-      w.write("-");
-    }
+  @Test
+  void testInvalidMagicLength() throws IOException {
+    assertThrows(InvalidAvroMagicException.class, () -> {
+      File f = Files.createTempFile("testInvalidMagicLength", 
".avro").toFile();
+      try (FileWriter w = new FileWriter(f)) {
+        w.write("-");
+      }
 
-    DataFileReader.openReader(new SeekableFileInput(f), new 
GenericDatumReader<>());
+      DataFileReader.openReader(new SeekableFileInput(f), new 
GenericDatumReader<>());
+    });
   }
 
-  @Test(expected = InvalidAvroMagicException.class)
-  public void testInvalidMagicBytes() throws IOException {
-    File f = Files.createTempFile("testInvalidMagicBytes", ".avro").toFile();
-    try (FileWriter w = new FileWriter(f)) {
-      w.write("invalid");
-    }
+  @Test
+  void testInvalidMagicBytes() throws IOException {
+    assertThrows(InvalidAvroMagicException.class, () -> {
+      File f = Files.createTempFile("testInvalidMagicBytes", ".avro").toFile();
+      try (FileWriter w = new FileWriter(f)) {
+        w.write("invalid");
+      }
 
-    DataFileReader.openReader(new SeekableFileInput(f), new 
GenericDatumReader<>());
+      DataFileReader.openReader(new SeekableFileInput(f), new 
GenericDatumReader<>());

Review Comment:
   ## Potential input resource leak
   
   This SeekableFileInput is not always closed on method exit.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/2805)



##########
lang/java/avro/src/test/java/org/apache/avro/TestDataFileReader.java:
##########
@@ -212,23 +213,27 @@
     }
   }
 
-  @Test(expected = InvalidAvroMagicException.class)
-  public void testInvalidMagicLength() throws IOException {
-    File f = Files.createTempFile("testInvalidMagicLength", ".avro").toFile();
-    try (FileWriter w = new FileWriter(f)) {
-      w.write("-");
-    }
+  @Test
+  void testInvalidMagicLength() throws IOException {
+    assertThrows(InvalidAvroMagicException.class, () -> {
+      File f = Files.createTempFile("testInvalidMagicLength", 
".avro").toFile();
+      try (FileWriter w = new FileWriter(f)) {
+        w.write("-");
+      }
 
-    DataFileReader.openReader(new SeekableFileInput(f), new 
GenericDatumReader<>());
+      DataFileReader.openReader(new SeekableFileInput(f), new 
GenericDatumReader<>());

Review Comment:
   ## Potential input resource leak
   
   This SeekableFileInput is not always closed on method exit.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/2804)



##########
lang/java/compiler/src/test/java/org/apache/avro/compiler/schema/TestSchemas.java:
##########
@@ -150,103 +160,107 @@
~      }
~    }
~
~    public String get() {
~      return sb.toString();
~    }
   }
 
   @Test
-  public void testVisit1() {
+  void testVisit1() {
     String s1 = "{\"type\": \"record\", \"name\": \"t1\", \"fields\": [" + 
"{\"name\": \"f1\", \"type\": \"int\"}"
         + "]}";
-    Assert.assertEquals("t1.", Schemas.visit(new Schema.Parser().parse(s1), 
new TestVisitor()));
+    assertEquals("t1.", Schemas.visit(new Schema.Parser().parse(s1), new 
TestVisitor()));
   }
 
   @Test
-  public void testVisit2() {
+  void testVisit2() {
     String s2 = "{\"type\": \"record\", \"name\": \"c1\", \"fields\": [" + 
"{\"name\": \"f1\", \"type\": \"int\"}"
         + "]}";
-    Assert.assertEquals("c1.\"int\"!", Schemas.visit(new 
Schema.Parser().parse(s2), new TestVisitor()));
+    assertEquals("c1.\"int\"!", Schemas.visit(new Schema.Parser().parse(s2), 
new TestVisitor()));
 
   }
 
   @Test
-  public void testVisit3() {
+  void testVisit3() {
     String s3 = "{\"type\": \"record\", \"name\": \"ss1\", \"fields\": [" + 
"{\"name\": \"f1\", \"type\": \"int\"}"
         + "]}";
-    Assert.assertEquals("ss1.", Schemas.visit(new Schema.Parser().parse(s3), 
new TestVisitor()));
+    assertEquals("ss1.", Schemas.visit(new Schema.Parser().parse(s3), new 
TestVisitor()));
 
   }
 
   @Test
-  public void testVisit4() {
+  void testVisit4() {
     String s4 = "{\"type\": \"record\", \"name\": \"st1\", \"fields\": [" + 
"{\"name\": \"f1\", \"type\": \"int\"}"
         + "]}";
-    Assert.assertEquals("st1.!", Schemas.visit(new Schema.Parser().parse(s4), 
new TestVisitor()));
+    assertEquals("st1.!", Schemas.visit(new Schema.Parser().parse(s4), new 
TestVisitor()));
 
   }
 
   @Test
-  public void testVisit5() {
+  void testVisit5() {
     String s5 = "{\"type\": \"record\", \"name\": \"c1\", \"fields\": ["
         + "{\"name\": \"f1\", \"type\": {\"type\": \"record\", \"name\": 
\"c2\", \"fields\": "
         + "[{\"name\": \"f11\", \"type\": \"int\"}]}}," + "{\"name\": \"f2\", 
\"type\": \"long\"}" + "]}";
-    Assert.assertEquals("c1.c2.\"int\"!\"long\"!", Schemas.visit(new 
Schema.Parser().parse(s5), new TestVisitor()));
+    assertEquals("c1.c2.\"int\"!\"long\"!", Schemas.visit(new 
Schema.Parser().parse(s5), new TestVisitor()));
 
   }
 
   @Test
-  public void testVisit6() {
+  void testVisit6() {
     String s6 = "{\"type\": \"record\", \"name\": \"c1\", \"fields\": ["
         + "{\"name\": \"f1\", \"type\": {\"type\": \"record\", \"name\": 
\"ss2\", \"fields\": "
         + "[{\"name\": \"f11\", \"type\": \"int\"}]}}," + "{\"name\": \"f2\", 
\"type\": \"long\"}" + "]}";
-    Assert.assertEquals("c1.ss2.!", Schemas.visit(new 
Schema.Parser().parse(s6), new TestVisitor()));
+    assertEquals("c1.ss2.!", Schemas.visit(new Schema.Parser().parse(s6), new 
TestVisitor()));
 
   }
 
   @Test
-  public void testVisit7() {
+  void testVisit7() {
     String s7 = "{\"type\": \"record\", \"name\": \"c1\", \"fields\": ["
         + "{\"name\": \"f1\", \"type\": {\"type\": \"record\", \"name\": 
\"css2\", \"fields\": "
         + "[{\"name\": \"f11\", \"type\": \"int\"}]}}," + "{\"name\": \"f2\", 
\"type\": \"long\"}" + "]}";
-    Assert.assertEquals("c1.css2.\"int\"!!", Schemas.visit(new 
Schema.Parser().parse(s7), new TestVisitor()));
+    assertEquals("c1.css2.\"int\"!!", Schemas.visit(new 
Schema.Parser().parse(s7), new TestVisitor()));
   }
 
-  @Test(expected = UnsupportedOperationException.class)
-  public void testVisit8() {
-    String s8 = "{\"type\": \"record\", \"name\": \"c1\", \"fields\": ["
-        + "{\"name\": \"f1\", \"type\": {\"type\": \"record\", \"name\": 
\"cst2\", \"fields\": "
-        + "[{\"name\": \"f11\", \"type\": \"int\"}]}}," + "{\"name\": \"f2\", 
\"type\": \"int\"}" + "]}";
-    Schemas.visit(new Schema.Parser().parse(s8), new TestVisitor());
+  @Test
+  void testVisit8() {
+    assertThrows(UnsupportedOperationException.class, () -> {
+      String s8 = "{\"type\": \"record\", \"name\": \"c1\", \"fields\": ["
+          + "{\"name\": \"f1\", \"type\": {\"type\": \"record\", \"name\": 
\"cst2\", \"fields\": "
+          + "[{\"name\": \"f11\", \"type\": \"int\"}]}}," + "{\"name\": 
\"f2\", \"type\": \"int\"}" + "]}";
+      Schemas.visit(new Schema.Parser().parse(s8), new TestVisitor());
+    });
   }
 
   @Test
-  public void testVisit9() {
+  void testVisit9() {
     String s9 = "{\"type\": \"record\", \"name\": \"c1\", \"fields\": ["
         + "{\"name\": \"f1\", \"type\": {\"type\": \"record\", \"name\": 
\"ct2\", \"fields\": "
         + "[{\"name\": \"f11\", \"type\": \"int\"}]}}," + "{\"name\": \"f2\", 
\"type\": \"long\"}" + "]}";
-    Assert.assertEquals("c1.ct2.\"int\"!", Schemas.visit(new 
Schema.Parser().parse(s9), new TestVisitor()));
+    assertEquals("c1.ct2.\"int\"!", Schemas.visit(new 
Schema.Parser().parse(s9), new TestVisitor()));
   }
 
-  @Test(expected = UnsupportedOperationException.class)
-  public void testVisit10() {
-    String s10 = "{\"type\": \"record\", \"name\": \"c1\", \"fields\": ["
-        + "{\"name\": \"f1\", \"type\": {\"type\": \"record\", \"name\": 
\"ct2\", \"fields\": "
-        + "[{\"name\": \"f11\", \"type\": \"int\"}]}}," + "{\"name\": \"f2\", 
\"type\": \"int\"}" + "]}";
-    Schemas.visit(new Schema.Parser().parse(s10), new TestVisitor() {
-      public SchemaVisitorAction visitTerminal(Schema terminal) {
-        return SchemaVisitorAction.SKIP_SUBTREE;
-      }
+  @Test
+  void testVisit10() {
+    assertThrows(UnsupportedOperationException.class, () -> {
+      String s10 = "{\"type\": \"record\", \"name\": \"c1\", \"fields\": ["
+          + "{\"name\": \"f1\", \"type\": {\"type\": \"record\", \"name\": 
\"ct2\", \"fields\": "
+          + "[{\"name\": \"f11\", \"type\": \"int\"}]}}," + "{\"name\": 
\"f2\", \"type\": \"int\"}" + "]}";
+      Schemas.visit(new Schema.Parser().parse(s10), new TestVisitor() {
+        public SchemaVisitorAction visitTerminal(Schema terminal) {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [TestVisitor.visitTerminal](1); it is advisable to add 
an Override annotation.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/2794)



-- 
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