Skip to content

Commit a5e7b7b

Browse files
author
Jan Bobolz
authored
Merge pull request #145 from cryptimeleon/helpfulexception
Added helpful error message for @represented primitive types
2 parents fcf4b76 + 1b731f7 commit a5e7b7b

File tree

1 file changed

+8
-2
lines changed
  • src/main/java/org/cryptimeleon/math/serialization/annotations

1 file changed

+8
-2
lines changed

src/main/java/org/cryptimeleon/math/serialization/annotations/ReprUtil.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
* For more information, consult the <a href="https://upbcuk.github.io/docs/representations.html">documentation</a>.
5959
*/
6060
public class ReprUtil {
61+
static final String[] primitiveTypes = new String[] {"byte", "short", "int", "long", "float", "double", "boolean", "char"};
6162
static Pattern methodCallSeparator = Pattern.compile("::");
6263
/**
6364
* Maps representation restorer identifiers to the corresponding {@code RepresentationRestorer} instances.
@@ -438,6 +439,9 @@ protected static RepresentationHandler getHandlerWithRestorerString(Type type, S
438439
);
439440
}
440441

442+
if (Arrays.asList(primitiveTypes).contains(type.getTypeName()))
443+
throw new IllegalArgumentException("Cannot handle primitive type "+type.getTypeName()+". Use object wrapper types instead (like Integer or Boolean)");
444+
441445
throw new IllegalArgumentException("Don't know how to handle type " + type.getTypeName()
442446
+ " using restorer String \"" + restorerString + "\"");
443447
}
@@ -451,7 +455,6 @@ protected static RepresentationHandler getHandlerWithRestorerString(Type type, S
451455
protected static RepresentationHandler getHandlerWithoutRestorerString(Type type) {
452456
// For generic type we need to extract the raw type. Only for StandaloneRepresentable though, as stuff
453457
// like list and map handling can handle generic types by themselves.
454-
// TODO: What about DependentRepresentations?
455458
Type rawType = type;
456459
if (type instanceof ParameterizedType) {
457460
rawType = ((ParameterizedType) type).getRawType();
@@ -478,8 +481,11 @@ protected static RepresentationHandler getHandlerWithoutRestorerString(Type type
478481
return new MapRepresentationHandler(getHandlerWithoutRestorerString(keyType), getHandlerWithoutRestorerString(valueType), type);
479482
}
480483

484+
if (Arrays.asList(primitiveTypes).contains(type.getTypeName()))
485+
throw new IllegalArgumentException("Cannot handle primitive type "+type.getTypeName()+". Use object wrapper types instead (like Integer or Boolean)");
486+
481487
throw new IllegalArgumentException("Don't know how to handle type " + type.getTypeName()
482-
+ " using empty restorer String (you can add one within the @Represented annotation)");
488+
+ " using empty restorer String (you can add one within the @Represented annotation to manually specify how to recreate this type)");
483489
}
484490

485491
/**

0 commit comments

Comments
 (0)