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


##########
lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java:
##########
@@ -487,99 +488,48 @@
    */
   protected Class findStringClass(Schema schema) {
     String name = schema.getProp(GenericData.STRING_PROP);
-    if (name == null)
+    if (name == null) {
       return CharSequence.class;
-
-    switch (GenericData.StringType.valueOf(name)) {
-    case String:
+    }
+    if (GenericData.StringType.String.name().equals(name)) {
       return String.class;
-    default:
-      return CharSequence.class;
     }
+    return CharSequence.class;
   }
 
-  /**
-   * This class is used to reproduce part of IdentityHashMap in 
ConcurrentHashMap
-   * code.
-   */
-  private static final class IdentitySchemaKey {
-    private final Schema schema;
-
-    private final int hashcode;
-
-    public IdentitySchemaKey(Schema schema) {
-      this.schema = schema;
-      this.hashcode = System.identityHashCode(schema);
-    }
-
-    @Override
-    public int hashCode() {
-      return this.hashcode;
+  @SuppressWarnings("unchecked")
+  protected Object newInstanceFromString(Class c, String s) {
+    // For some of the more common classes, implement specific routines.
+    // For more complex classes, use reflection.
+    if (c == Integer.class) {
+      return Integer.parseInt(s, 10);
     }
-
-    @Override
-    public boolean equals(Object obj) {
-      if (obj == null || !(obj instanceof 
GenericDatumReader.IdentitySchemaKey)) {
-        return false;
-      }
-      IdentitySchemaKey key = (IdentitySchemaKey) obj;
-      return this == key || this.schema == key.schema;
+    if (c == Long.class) {
+      return Long.parseLong(s, 10);

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/3299)



##########
lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java:
##########
@@ -487,99 +488,48 @@
    */
   protected Class findStringClass(Schema schema) {
     String name = schema.getProp(GenericData.STRING_PROP);
-    if (name == null)
+    if (name == null) {
       return CharSequence.class;
-
-    switch (GenericData.StringType.valueOf(name)) {
-    case String:
+    }
+    if (GenericData.StringType.String.name().equals(name)) {
       return String.class;
-    default:
-      return CharSequence.class;
     }
+    return CharSequence.class;
   }
 
-  /**
-   * This class is used to reproduce part of IdentityHashMap in 
ConcurrentHashMap
-   * code.
-   */
-  private static final class IdentitySchemaKey {
-    private final Schema schema;
-
-    private final int hashcode;
-
-    public IdentitySchemaKey(Schema schema) {
-      this.schema = schema;
-      this.hashcode = System.identityHashCode(schema);
-    }
-
-    @Override
-    public int hashCode() {
-      return this.hashcode;
+  @SuppressWarnings("unchecked")
+  protected Object newInstanceFromString(Class c, String s) {
+    // For some of the more common classes, implement specific routines.
+    // For more complex classes, use reflection.
+    if (c == Integer.class) {
+      return Integer.parseInt(s, 10);
     }
-
-    @Override
-    public boolean equals(Object obj) {
-      if (obj == null || !(obj instanceof 
GenericDatumReader.IdentitySchemaKey)) {
-        return false;
-      }
-      IdentitySchemaKey key = (IdentitySchemaKey) obj;
-      return this == key || this.schema == key.schema;
+    if (c == Long.class) {
+      return Long.parseLong(s, 10);
     }
-  }
-
-  // VisibleForTesting
-  static class ReaderCache {
-    private final Map<IdentitySchemaKey, Class> stringClassCache = new 
ConcurrentHashMap<>();
-
-    private final Map<Class, Function<String, Object>> stringCtorCache = new 
ConcurrentHashMap<>();
-
-    private final Function<Schema, Class> findStringClass;
-
-    public ReaderCache(Function<Schema, Class> findStringClass) {
-      this.findStringClass = findStringClass;
+    if (c == Float.class) {
+      return Float.parseFloat(s);
     }
-
-    public Object newInstanceFromString(Class c, String s) {
-      final Function<String, Object> ctor = stringCtorCache.computeIfAbsent(c, 
this::buildFunction);
-      return ctor.apply(s);
+    if (c == Double.class) {
+      return Double.parseDouble(s);

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/3301)



##########
lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java:
##########
@@ -487,99 +488,48 @@
    */
   protected Class findStringClass(Schema schema) {
     String name = schema.getProp(GenericData.STRING_PROP);
-    if (name == null)
+    if (name == null) {
       return CharSequence.class;
-
-    switch (GenericData.StringType.valueOf(name)) {
-    case String:
+    }
+    if (GenericData.StringType.String.name().equals(name)) {
       return String.class;
-    default:
-      return CharSequence.class;
     }
+    return CharSequence.class;
   }
 
-  /**
-   * This class is used to reproduce part of IdentityHashMap in 
ConcurrentHashMap
-   * code.
-   */
-  private static final class IdentitySchemaKey {
-    private final Schema schema;
-
-    private final int hashcode;
-
-    public IdentitySchemaKey(Schema schema) {
-      this.schema = schema;
-      this.hashcode = System.identityHashCode(schema);
-    }
-
-    @Override
-    public int hashCode() {
-      return this.hashcode;
+  @SuppressWarnings("unchecked")
+  protected Object newInstanceFromString(Class c, String s) {
+    // For some of the more common classes, implement specific routines.
+    // For more complex classes, use reflection.
+    if (c == Integer.class) {
+      return Integer.parseInt(s, 10);

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/3298)



##########
lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java:
##########
@@ -487,99 +488,48 @@
    */
   protected Class findStringClass(Schema schema) {
     String name = schema.getProp(GenericData.STRING_PROP);
-    if (name == null)
+    if (name == null) {
       return CharSequence.class;
-
-    switch (GenericData.StringType.valueOf(name)) {
-    case String:
+    }
+    if (GenericData.StringType.String.name().equals(name)) {
       return String.class;
-    default:
-      return CharSequence.class;
     }
+    return CharSequence.class;
   }
 
-  /**
-   * This class is used to reproduce part of IdentityHashMap in 
ConcurrentHashMap
-   * code.
-   */
-  private static final class IdentitySchemaKey {
-    private final Schema schema;
-
-    private final int hashcode;
-
-    public IdentitySchemaKey(Schema schema) {
-      this.schema = schema;
-      this.hashcode = System.identityHashCode(schema);
-    }
-
-    @Override
-    public int hashCode() {
-      return this.hashcode;
+  @SuppressWarnings("unchecked")
+  protected Object newInstanceFromString(Class c, String s) {
+    // For some of the more common classes, implement specific routines.
+    // For more complex classes, use reflection.
+    if (c == Integer.class) {
+      return Integer.parseInt(s, 10);
     }
-
-    @Override
-    public boolean equals(Object obj) {
-      if (obj == null || !(obj instanceof 
GenericDatumReader.IdentitySchemaKey)) {
-        return false;
-      }
-      IdentitySchemaKey key = (IdentitySchemaKey) obj;
-      return this == key || this.schema == key.schema;
+    if (c == Long.class) {
+      return Long.parseLong(s, 10);
     }
-  }
-
-  // VisibleForTesting
-  static class ReaderCache {
-    private final Map<IdentitySchemaKey, Class> stringClassCache = new 
ConcurrentHashMap<>();
-
-    private final Map<Class, Function<String, Object>> stringCtorCache = new 
ConcurrentHashMap<>();
-
-    private final Function<Schema, Class> findStringClass;
-
-    public ReaderCache(Function<Schema, Class> findStringClass) {
-      this.findStringClass = findStringClass;
+    if (c == Float.class) {
+      return Float.parseFloat(s);

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/3300)



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