[add] better exception messaging. Project: http://git-wip-us.apache.org/repos/asf/avro/repo Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/21efba08 Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/21efba08 Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/21efba08
Branch: refs/heads/master Commit: 21efba087b9fec37500b59e21a8bf5be546ea5a8 Parents: cc224ab Author: Zoltan Farkas <[email protected]> Authored: Sun Apr 17 23:30:10 2016 -0400 Committer: Zoltan Farkas <[email protected]> Committed: Sun Apr 17 23:30:10 2016 -0400 ---------------------------------------------------------------------- .../apache/avro/compiler/idl/SchemaResolver.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/avro/blob/21efba08/lang/java/compiler/src/main/java/org/apache/avro/compiler/idl/SchemaResolver.java ---------------------------------------------------------------------- diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/idl/SchemaResolver.java b/lang/java/compiler/src/main/java/org/apache/avro/compiler/idl/SchemaResolver.java index 6d897ca..56386b3 100644 --- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/idl/SchemaResolver.java +++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/idl/SchemaResolver.java @@ -38,9 +38,15 @@ final class SchemaResolver { private static final String UR_SCHEMA_ATTR = "org.apache.avro.compiler.idl.unresolved.name"; + private static final String UR_SCHEMA_NAME = "UnresolvedSchema"; + + private static final String UR_SCHEMA_NS = "org.apache.avro.compiler"; + static Schema unresolvedSchema(final String name) { - Schema schema = Schema.createRecord("UnresolvedSchema", "unresolved schema", - "org.apache.avro.compiler", false, Collections.EMPTY_LIST); + + + Schema schema = Schema.createRecord(UR_SCHEMA_NAME, "unresolved schema", + UR_SCHEMA_NS, false, Collections.EMPTY_LIST); schema.addProp(UR_SCHEMA_ATTR, name); return schema; } @@ -50,9 +56,13 @@ final class SchemaResolver { } static String getUnresolvedSchemaName(final Schema schema) { + if (schema.getType() != Schema.Type.RECORD || !UR_SCHEMA_NAME.equals(schema.getName()) + || !UR_SCHEMA_NS.equals(schema.getNamespace())) { + throw new IllegalArgumentException("Not a unresolved schema: " + schema); + } String name = schema.getProp(UR_SCHEMA_ATTR); if (name == null) { - throw new IllegalArgumentException("Schema " + schema + " is not a unresolved schema"); + throw new IllegalArgumentException("Schema " + schema + " must have attribute: " + UR_SCHEMA_ATTR); } else { return name; }
