opwvhk commented on a change in pull request #1277:
URL: https://github.com/apache/avro/pull/1277#discussion_r778809555



##########
File path: 
lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
##########
@@ -874,6 +874,40 @@ public int getNonNullIndex(Schema s) {
     return (s.getTypes().get(0).equals(NULL_SCHEMA) ? 1 : 0);
   }
 
+  /**
+   * Utility for template use. Returns true if specified java-class is 
stringable
+   * and should be deserialized using constructor with String.
+   */
+  public boolean shouldBeDeserializedFromString(Schema schema) {
+    try {
+      Class<?> clazz = Class.forName(javaType(schema));
+      return specificData.isStringable(clazz);
+    } catch (ClassNotFoundException e) {
+      return false;
+    }
+  }
+
+  /**
+   * Utility for template use. Returns true constructor that accepts string
+   * parameter (e.g. new URL(string)) throws checked exception.
+   */
+  public boolean constructorThrowsCheckedException(Schema schema) {
+    try {
+      Class<?> clazz = Class.forName(javaType(schema));
+      Class<?>[] possibleExceptions = 
clazz.getDeclaredConstructor(String.class).getExceptionTypes();
+      for (Class<?> exceptionClass : possibleExceptions) {
+        if (!Error.class.isAssignableFrom(exceptionClass) && 
!RuntimeException.class.isAssignableFrom(exceptionClass)) {
+          return true;
+        }
+      }
+      return false;
+    } catch (ClassNotFoundException e) {
+      throw new RuntimeException("Unable to find class " + javaType(schema), 
e);

Review comment:
       Instead of a bare `RuntimeException`, is shouldn't we throw 
`AvroRuntimeException` ?




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