Skip to content

Commit

Permalink
Merge pull request #145 from cryptimeleon/helpfulexception
Browse files Browse the repository at this point in the history
Added helpful error message for @represented primitive types
  • Loading branch information
Jan Bobolz authored Nov 3, 2021
2 parents fcf4b76 + 1b731f7 commit a5e7b7b
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
* For more information, consult the <a href="https://upbcuk.github.io/docs/representations.html">documentation</a>.
*/
public class ReprUtil {
static final String[] primitiveTypes = new String[] {"byte", "short", "int", "long", "float", "double", "boolean", "char"};
static Pattern methodCallSeparator = Pattern.compile("::");
/**
* Maps representation restorer identifiers to the corresponding {@code RepresentationRestorer} instances.
Expand Down Expand Up @@ -438,6 +439,9 @@ protected static RepresentationHandler getHandlerWithRestorerString(Type type, S
);
}

if (Arrays.asList(primitiveTypes).contains(type.getTypeName()))
throw new IllegalArgumentException("Cannot handle primitive type "+type.getTypeName()+". Use object wrapper types instead (like Integer or Boolean)");

throw new IllegalArgumentException("Don't know how to handle type " + type.getTypeName()
+ " using restorer String \"" + restorerString + "\"");
}
Expand All @@ -451,7 +455,6 @@ protected static RepresentationHandler getHandlerWithRestorerString(Type type, S
protected static RepresentationHandler getHandlerWithoutRestorerString(Type type) {
// For generic type we need to extract the raw type. Only for StandaloneRepresentable though, as stuff
// like list and map handling can handle generic types by themselves.
// TODO: What about DependentRepresentations?
Type rawType = type;
if (type instanceof ParameterizedType) {
rawType = ((ParameterizedType) type).getRawType();
Expand All @@ -478,8 +481,11 @@ protected static RepresentationHandler getHandlerWithoutRestorerString(Type type
return new MapRepresentationHandler(getHandlerWithoutRestorerString(keyType), getHandlerWithoutRestorerString(valueType), type);
}

if (Arrays.asList(primitiveTypes).contains(type.getTypeName()))
throw new IllegalArgumentException("Cannot handle primitive type "+type.getTypeName()+". Use object wrapper types instead (like Integer or Boolean)");

throw new IllegalArgumentException("Don't know how to handle type " + type.getTypeName()
+ " using empty restorer String (you can add one within the @Represented annotation)");
+ " using empty restorer String (you can add one within the @Represented annotation to manually specify how to recreate this type)");
}

/**
Expand Down

0 comments on commit a5e7b7b

Please sign in to comment.