github-advanced-security[bot] commented on code in PR #2513:
URL: https://github.com/apache/avro/pull/2513#discussion_r1373095935


##########
lang/java/avro/src/test/java/org/apache/avro/ParseContextTest.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.EnumSet;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ParseContextTest {
+  Schema fooRecord, fooRecordCopy, barEnum, bazFixed, mehRecord;
+  ParseContext fooBarBaz;
+
+  @BeforeEach
+  public void setUp() throws Exception {
+    fooRecord = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    fooRecordCopy = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    barEnum = SchemaBuilder.enumeration("ns.Bar").symbols();
+    bazFixed = SchemaBuilder.fixed("ns.Baz").size(8);
+    mehRecord = SchemaBuilder.record("ns.Meh").fields().endRecord();
+
+    fooBarBaz = new ParseContext();
+    fooBarBaz.put(fooRecord);
+    fooBarBaz.put(barEnum);
+    fooBarBaz.put(bazFixed);
+  }
+
+  @Test
+  public void checkNewNameContextContainsPrimitives() {
+    EnumSet<Schema.Type> complexTypes = EnumSet.of(Schema.Type.RECORD, 
Schema.Type.ENUM, Schema.Type.FIXED,
+        Schema.Type.UNION, Schema.Type.ARRAY, Schema.Type.MAP);
+    EnumSet<Schema.Type> primitives = EnumSet.complementOf(complexTypes);
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : complexTypes) {
+      assertFalse(context.contains(type.getName()));
+    }
+    for (Schema.Type type : primitives) {
+      assertTrue(context.contains(type.getName()));
+    }
+  }
+
+  @Test
+  public void primitivesAreNotCached() {
+    EnumSet<Schema.Type> primitives = 
EnumSet.complementOf(EnumSet.of(Schema.Type.RECORD, Schema.Type.ENUM,
+        Schema.Type.FIXED, Schema.Type.UNION, Schema.Type.ARRAY, 
Schema.Type.MAP));
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : primitives) {
+      Schema first = context.resolve(type.getName());
+      Schema second = context.resolve(type.getName());
+      assertEquals(first, second);
+      assertNotSame(first, second);
+
+      first.addProp("logicalType", "brick");
+      assertNotEquals(first, second);
+    }
+  }
+
+  @Test
+  public void validateSchemaTests() {
+    assertTrue(fooBarBaz.contains(fooRecord));

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ParseContext.contains](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/3138)



##########
lang/java/avro/src/test/java/org/apache/avro/ParseContextTest.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.EnumSet;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ParseContextTest {
+  Schema fooRecord, fooRecordCopy, barEnum, bazFixed, mehRecord;
+  ParseContext fooBarBaz;
+
+  @BeforeEach
+  public void setUp() throws Exception {
+    fooRecord = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    fooRecordCopy = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    barEnum = SchemaBuilder.enumeration("ns.Bar").symbols();
+    bazFixed = SchemaBuilder.fixed("ns.Baz").size(8);
+    mehRecord = SchemaBuilder.record("ns.Meh").fields().endRecord();
+
+    fooBarBaz = new ParseContext();
+    fooBarBaz.put(fooRecord);
+    fooBarBaz.put(barEnum);
+    fooBarBaz.put(bazFixed);
+  }
+
+  @Test
+  public void checkNewNameContextContainsPrimitives() {
+    EnumSet<Schema.Type> complexTypes = EnumSet.of(Schema.Type.RECORD, 
Schema.Type.ENUM, Schema.Type.FIXED,
+        Schema.Type.UNION, Schema.Type.ARRAY, Schema.Type.MAP);
+    EnumSet<Schema.Type> primitives = EnumSet.complementOf(complexTypes);
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : complexTypes) {
+      assertFalse(context.contains(type.getName()));
+    }
+    for (Schema.Type type : primitives) {
+      assertTrue(context.contains(type.getName()));
+    }
+  }
+
+  @Test
+  public void primitivesAreNotCached() {
+    EnumSet<Schema.Type> primitives = 
EnumSet.complementOf(EnumSet.of(Schema.Type.RECORD, Schema.Type.ENUM,
+        Schema.Type.FIXED, Schema.Type.UNION, Schema.Type.ARRAY, 
Schema.Type.MAP));
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : primitives) {
+      Schema first = context.resolve(type.getName());
+      Schema second = context.resolve(type.getName());
+      assertEquals(first, second);
+      assertNotSame(first, second);
+
+      first.addProp("logicalType", "brick");
+      assertNotEquals(first, second);
+    }
+  }
+
+  @Test
+  public void validateSchemaTests() {
+    assertTrue(fooBarBaz.contains(fooRecord));
+    assertTrue(fooBarBaz.contains(barEnum));

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ParseContext.contains](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/3139)



##########
lang/java/avro/src/test/java/org/apache/avro/ParseContextTest.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.EnumSet;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ParseContextTest {
+  Schema fooRecord, fooRecordCopy, barEnum, bazFixed, mehRecord;
+  ParseContext fooBarBaz;
+
+  @BeforeEach
+  public void setUp() throws Exception {
+    fooRecord = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    fooRecordCopy = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    barEnum = SchemaBuilder.enumeration("ns.Bar").symbols();
+    bazFixed = SchemaBuilder.fixed("ns.Baz").size(8);
+    mehRecord = SchemaBuilder.record("ns.Meh").fields().endRecord();
+
+    fooBarBaz = new ParseContext();
+    fooBarBaz.put(fooRecord);
+    fooBarBaz.put(barEnum);
+    fooBarBaz.put(bazFixed);
+  }
+
+  @Test
+  public void checkNewNameContextContainsPrimitives() {
+    EnumSet<Schema.Type> complexTypes = EnumSet.of(Schema.Type.RECORD, 
Schema.Type.ENUM, Schema.Type.FIXED,
+        Schema.Type.UNION, Schema.Type.ARRAY, Schema.Type.MAP);
+    EnumSet<Schema.Type> primitives = EnumSet.complementOf(complexTypes);
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : complexTypes) {
+      assertFalse(context.contains(type.getName()));
+    }
+    for (Schema.Type type : primitives) {
+      assertTrue(context.contains(type.getName()));
+    }
+  }
+
+  @Test
+  public void primitivesAreNotCached() {
+    EnumSet<Schema.Type> primitives = 
EnumSet.complementOf(EnumSet.of(Schema.Type.RECORD, Schema.Type.ENUM,
+        Schema.Type.FIXED, Schema.Type.UNION, Schema.Type.ARRAY, 
Schema.Type.MAP));
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : primitives) {
+      Schema first = context.resolve(type.getName());
+      Schema second = context.resolve(type.getName());
+      assertEquals(first, second);
+      assertNotSame(first, second);
+
+      first.addProp("logicalType", "brick");
+      assertNotEquals(first, second);
+    }
+  }
+
+  @Test
+  public void validateSchemaTests() {
+    assertTrue(fooBarBaz.contains(fooRecord));
+    assertTrue(fooBarBaz.contains(barEnum));
+    assertTrue(fooBarBaz.contains(bazFixed));
+    assertFalse(fooBarBaz.contains(mehRecord));

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ParseContext.contains](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/3141)



##########
lang/java/avro/src/test/java/org/apache/avro/ParseContextTest.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.EnumSet;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ParseContextTest {
+  Schema fooRecord, fooRecordCopy, barEnum, bazFixed, mehRecord;
+  ParseContext fooBarBaz;
+
+  @BeforeEach
+  public void setUp() throws Exception {
+    fooRecord = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    fooRecordCopy = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    barEnum = SchemaBuilder.enumeration("ns.Bar").symbols();
+    bazFixed = SchemaBuilder.fixed("ns.Baz").size(8);
+    mehRecord = SchemaBuilder.record("ns.Meh").fields().endRecord();
+
+    fooBarBaz = new ParseContext();
+    fooBarBaz.put(fooRecord);
+    fooBarBaz.put(barEnum);
+    fooBarBaz.put(bazFixed);
+  }
+
+  @Test
+  public void checkNewNameContextContainsPrimitives() {
+    EnumSet<Schema.Type> complexTypes = EnumSet.of(Schema.Type.RECORD, 
Schema.Type.ENUM, Schema.Type.FIXED,
+        Schema.Type.UNION, Schema.Type.ARRAY, Schema.Type.MAP);
+    EnumSet<Schema.Type> primitives = EnumSet.complementOf(complexTypes);
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : complexTypes) {
+      assertFalse(context.contains(type.getName()));
+    }
+    for (Schema.Type type : primitives) {
+      assertTrue(context.contains(type.getName()));
+    }
+  }
+
+  @Test
+  public void primitivesAreNotCached() {
+    EnumSet<Schema.Type> primitives = 
EnumSet.complementOf(EnumSet.of(Schema.Type.RECORD, Schema.Type.ENUM,
+        Schema.Type.FIXED, Schema.Type.UNION, Schema.Type.ARRAY, 
Schema.Type.MAP));
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : primitives) {
+      Schema first = context.resolve(type.getName());
+      Schema second = context.resolve(type.getName());
+      assertEquals(first, second);
+      assertNotSame(first, second);
+
+      first.addProp("logicalType", "brick");
+      assertNotEquals(first, second);
+    }
+  }
+
+  @Test
+  public void validateSchemaTests() {
+    assertTrue(fooBarBaz.contains(fooRecord));
+    assertTrue(fooBarBaz.contains(barEnum));
+    assertTrue(fooBarBaz.contains(bazFixed));
+    assertFalse(fooBarBaz.contains(mehRecord));
+
+    assertTrue(fooBarBaz.contains(fooRecord.getFullName()));
+    assertTrue(fooBarBaz.contains(barEnum.getFullName()));
+    assertTrue(fooBarBaz.contains(bazFixed.getFullName()));
+    assertFalse(fooBarBaz.contains(mehRecord.getFullName()));
+  }
+
+  @Test
+  public void validateNameResolvingAgainstDefaultNamespace() {
+    ParseContext context = new ParseContext("");
+    assertEquals("Bar", context.resolveName("Bar", ""));
+    assertEquals("Bar", context.resolveName("Bar", null));
+    assertEquals("foo.Bar", context.resolveName("Bar", "foo"));
+  }
+
+  @Test
+  public void validateNameResolvingAgainstSetNamespace() {
+    ParseContext context = new ParseContext("ns");
+    assertEquals("ns.Bar", context.resolveName("Bar", ""));
+    assertEquals("ns.Bar", context.resolveName("Bar", null));
+    assertEquals("foo.Bar", context.resolveName("Bar", "foo"));
+  }
+
+  @Test
+  public void validateSchemaRetrievalFailure() {
+    Schema unknown = Schema.createFixed("unknown", null, null, 0);
+
+    assertThrows(AvroRuntimeException.class, () -> 
fooBarBaz.resolve("unknown"));
+    assertSame(unknown, fooBarBaz.resolve("unknown"));
+  }
+
+  @Test
+  public void validateSchemaRetrievalByFullName() {
+    assertSame(fooRecord, fooBarBaz.resolve(fooRecord.getFullName()));
+  }
+
+  @Test
+  public void validateSchemaRetrievalByNameAndInheritedNamespace() {
+    assertSame(fooRecord, 
fooBarBaz.namespace(fooRecord.getNamespace()).resolve(fooRecord.getName()));
+  }
+
+  @Test
+  public void verifyPutIsIdempotent() {
+    ParseContext context = new ParseContext();
+    assertFalse(context.contains(fooRecord));
+
+    context.put(fooRecord);
+    assertTrue(context.contains(fooRecord));

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ParseContext.contains](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/3143)



##########
lang/java/avro/src/test/java/org/apache/avro/ParseContextTest.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.EnumSet;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ParseContextTest {
+  Schema fooRecord, fooRecordCopy, barEnum, bazFixed, mehRecord;
+  ParseContext fooBarBaz;
+
+  @BeforeEach
+  public void setUp() throws Exception {
+    fooRecord = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    fooRecordCopy = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    barEnum = SchemaBuilder.enumeration("ns.Bar").symbols();
+    bazFixed = SchemaBuilder.fixed("ns.Baz").size(8);
+    mehRecord = SchemaBuilder.record("ns.Meh").fields().endRecord();
+
+    fooBarBaz = new ParseContext();
+    fooBarBaz.put(fooRecord);
+    fooBarBaz.put(barEnum);
+    fooBarBaz.put(bazFixed);
+  }
+
+  @Test
+  public void checkNewNameContextContainsPrimitives() {
+    EnumSet<Schema.Type> complexTypes = EnumSet.of(Schema.Type.RECORD, 
Schema.Type.ENUM, Schema.Type.FIXED,
+        Schema.Type.UNION, Schema.Type.ARRAY, Schema.Type.MAP);
+    EnumSet<Schema.Type> primitives = EnumSet.complementOf(complexTypes);
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : complexTypes) {
+      assertFalse(context.contains(type.getName()));
+    }
+    for (Schema.Type type : primitives) {
+      assertTrue(context.contains(type.getName()));
+    }
+  }
+
+  @Test
+  public void primitivesAreNotCached() {
+    EnumSet<Schema.Type> primitives = 
EnumSet.complementOf(EnumSet.of(Schema.Type.RECORD, Schema.Type.ENUM,
+        Schema.Type.FIXED, Schema.Type.UNION, Schema.Type.ARRAY, 
Schema.Type.MAP));
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : primitives) {
+      Schema first = context.resolve(type.getName());
+      Schema second = context.resolve(type.getName());
+      assertEquals(first, second);
+      assertNotSame(first, second);
+
+      first.addProp("logicalType", "brick");
+      assertNotEquals(first, second);
+    }
+  }
+
+  @Test
+  public void validateSchemaTests() {
+    assertTrue(fooBarBaz.contains(fooRecord));
+    assertTrue(fooBarBaz.contains(barEnum));
+    assertTrue(fooBarBaz.contains(bazFixed));
+    assertFalse(fooBarBaz.contains(mehRecord));
+
+    assertTrue(fooBarBaz.contains(fooRecord.getFullName()));
+    assertTrue(fooBarBaz.contains(barEnum.getFullName()));
+    assertTrue(fooBarBaz.contains(bazFixed.getFullName()));
+    assertFalse(fooBarBaz.contains(mehRecord.getFullName()));
+  }
+
+  @Test
+  public void validateNameResolvingAgainstDefaultNamespace() {
+    ParseContext context = new ParseContext("");
+    assertEquals("Bar", context.resolveName("Bar", ""));
+    assertEquals("Bar", context.resolveName("Bar", null));
+    assertEquals("foo.Bar", context.resolveName("Bar", "foo"));
+  }
+
+  @Test
+  public void validateNameResolvingAgainstSetNamespace() {
+    ParseContext context = new ParseContext("ns");
+    assertEquals("ns.Bar", context.resolveName("Bar", ""));
+    assertEquals("ns.Bar", context.resolveName("Bar", null));
+    assertEquals("foo.Bar", context.resolveName("Bar", "foo"));
+  }
+
+  @Test
+  public void validateSchemaRetrievalFailure() {
+    Schema unknown = Schema.createFixed("unknown", null, null, 0);
+
+    assertThrows(AvroRuntimeException.class, () -> 
fooBarBaz.resolve("unknown"));
+    assertSame(unknown, fooBarBaz.resolve("unknown"));
+  }
+
+  @Test
+  public void validateSchemaRetrievalByFullName() {
+    assertSame(fooRecord, fooBarBaz.resolve(fooRecord.getFullName()));
+  }
+
+  @Test
+  public void validateSchemaRetrievalByNameAndInheritedNamespace() {
+    assertSame(fooRecord, 
fooBarBaz.namespace(fooRecord.getNamespace()).resolve(fooRecord.getName()));
+  }
+
+  @Test
+  public void verifyPutIsIdempotent() {
+    ParseContext context = new ParseContext();
+    assertFalse(context.contains(fooRecord));
+
+    context.put(fooRecord);
+    assertTrue(context.contains(fooRecord));
+
+    context.put(fooRecord);
+    assertTrue(context.contains(fooRecord));

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ParseContext.contains](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/3144)



##########
lang/java/avro/src/test/java/org/apache/avro/ParseContextTest.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.EnumSet;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ParseContextTest {
+  Schema fooRecord, fooRecordCopy, barEnum, bazFixed, mehRecord;
+  ParseContext fooBarBaz;
+
+  @BeforeEach
+  public void setUp() throws Exception {
+    fooRecord = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    fooRecordCopy = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    barEnum = SchemaBuilder.enumeration("ns.Bar").symbols();
+    bazFixed = SchemaBuilder.fixed("ns.Baz").size(8);
+    mehRecord = SchemaBuilder.record("ns.Meh").fields().endRecord();
+
+    fooBarBaz = new ParseContext();
+    fooBarBaz.put(fooRecord);
+    fooBarBaz.put(barEnum);
+    fooBarBaz.put(bazFixed);
+  }
+
+  @Test
+  public void checkNewNameContextContainsPrimitives() {
+    EnumSet<Schema.Type> complexTypes = EnumSet.of(Schema.Type.RECORD, 
Schema.Type.ENUM, Schema.Type.FIXED,
+        Schema.Type.UNION, Schema.Type.ARRAY, Schema.Type.MAP);
+    EnumSet<Schema.Type> primitives = EnumSet.complementOf(complexTypes);
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : complexTypes) {
+      assertFalse(context.contains(type.getName()));
+    }
+    for (Schema.Type type : primitives) {
+      assertTrue(context.contains(type.getName()));
+    }
+  }
+
+  @Test
+  public void primitivesAreNotCached() {
+    EnumSet<Schema.Type> primitives = 
EnumSet.complementOf(EnumSet.of(Schema.Type.RECORD, Schema.Type.ENUM,
+        Schema.Type.FIXED, Schema.Type.UNION, Schema.Type.ARRAY, 
Schema.Type.MAP));
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : primitives) {
+      Schema first = context.resolve(type.getName());
+      Schema second = context.resolve(type.getName());
+      assertEquals(first, second);
+      assertNotSame(first, second);
+
+      first.addProp("logicalType", "brick");
+      assertNotEquals(first, second);
+    }
+  }
+
+  @Test
+  public void validateSchemaTests() {
+    assertTrue(fooBarBaz.contains(fooRecord));
+    assertTrue(fooBarBaz.contains(barEnum));
+    assertTrue(fooBarBaz.contains(bazFixed));
+    assertFalse(fooBarBaz.contains(mehRecord));
+
+    assertTrue(fooBarBaz.contains(fooRecord.getFullName()));
+    assertTrue(fooBarBaz.contains(barEnum.getFullName()));
+    assertTrue(fooBarBaz.contains(bazFixed.getFullName()));
+    assertFalse(fooBarBaz.contains(mehRecord.getFullName()));
+  }
+
+  @Test
+  public void validateNameResolvingAgainstDefaultNamespace() {
+    ParseContext context = new ParseContext("");
+    assertEquals("Bar", context.resolveName("Bar", ""));
+    assertEquals("Bar", context.resolveName("Bar", null));
+    assertEquals("foo.Bar", context.resolveName("Bar", "foo"));
+  }
+
+  @Test
+  public void validateNameResolvingAgainstSetNamespace() {
+    ParseContext context = new ParseContext("ns");
+    assertEquals("ns.Bar", context.resolveName("Bar", ""));
+    assertEquals("ns.Bar", context.resolveName("Bar", null));
+    assertEquals("foo.Bar", context.resolveName("Bar", "foo"));
+  }
+
+  @Test
+  public void validateSchemaRetrievalFailure() {
+    Schema unknown = Schema.createFixed("unknown", null, null, 0);
+
+    assertThrows(AvroRuntimeException.class, () -> 
fooBarBaz.resolve("unknown"));
+    assertSame(unknown, fooBarBaz.resolve("unknown"));
+  }
+
+  @Test
+  public void validateSchemaRetrievalByFullName() {
+    assertSame(fooRecord, fooBarBaz.resolve(fooRecord.getFullName()));
+  }
+
+  @Test
+  public void validateSchemaRetrievalByNameAndInheritedNamespace() {
+    assertSame(fooRecord, 
fooBarBaz.namespace(fooRecord.getNamespace()).resolve(fooRecord.getName()));
+  }
+
+  @Test
+  public void verifyPutIsIdempotent() {
+    ParseContext context = new ParseContext();
+    assertFalse(context.contains(fooRecord));

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ParseContext.contains](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/3142)



##########
lang/java/avro/src/test/java/org/apache/avro/ParseContextTest.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.EnumSet;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ParseContextTest {
+  Schema fooRecord, fooRecordCopy, barEnum, bazFixed, mehRecord;
+  ParseContext fooBarBaz;
+
+  @BeforeEach
+  public void setUp() throws Exception {
+    fooRecord = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    fooRecordCopy = SchemaBuilder.record("ns.Foo").fields().endRecord();
+    barEnum = SchemaBuilder.enumeration("ns.Bar").symbols();
+    bazFixed = SchemaBuilder.fixed("ns.Baz").size(8);
+    mehRecord = SchemaBuilder.record("ns.Meh").fields().endRecord();
+
+    fooBarBaz = new ParseContext();
+    fooBarBaz.put(fooRecord);
+    fooBarBaz.put(barEnum);
+    fooBarBaz.put(bazFixed);
+  }
+
+  @Test
+  public void checkNewNameContextContainsPrimitives() {
+    EnumSet<Schema.Type> complexTypes = EnumSet.of(Schema.Type.RECORD, 
Schema.Type.ENUM, Schema.Type.FIXED,
+        Schema.Type.UNION, Schema.Type.ARRAY, Schema.Type.MAP);
+    EnumSet<Schema.Type> primitives = EnumSet.complementOf(complexTypes);
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : complexTypes) {
+      assertFalse(context.contains(type.getName()));
+    }
+    for (Schema.Type type : primitives) {
+      assertTrue(context.contains(type.getName()));
+    }
+  }
+
+  @Test
+  public void primitivesAreNotCached() {
+    EnumSet<Schema.Type> primitives = 
EnumSet.complementOf(EnumSet.of(Schema.Type.RECORD, Schema.Type.ENUM,
+        Schema.Type.FIXED, Schema.Type.UNION, Schema.Type.ARRAY, 
Schema.Type.MAP));
+
+    ParseContext context = new ParseContext();
+    for (Schema.Type type : primitives) {
+      Schema first = context.resolve(type.getName());
+      Schema second = context.resolve(type.getName());
+      assertEquals(first, second);
+      assertNotSame(first, second);
+
+      first.addProp("logicalType", "brick");
+      assertNotEquals(first, second);
+    }
+  }
+
+  @Test
+  public void validateSchemaTests() {
+    assertTrue(fooBarBaz.contains(fooRecord));
+    assertTrue(fooBarBaz.contains(barEnum));
+    assertTrue(fooBarBaz.contains(bazFixed));

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ParseContext.contains](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/3140)



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