Skip to content

Commit

Permalink
Merge pull request EsotericSoftware#518 from garfieldnate/patch-1
Browse files Browse the repository at this point in the history
error message for problems with anonymous classes
  • Loading branch information
magro authored Jun 11, 2017
2 parents 6455ae5 + 0eb7b71 commit 4ac9c4c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/com/esotericsoftware/kryo/Kryo.java
Original file line number Diff line number Diff line change
Expand Up @@ -1306,8 +1306,18 @@ public Object newInstance () {
if (fallbackStrategy == null) {
if (type.isMemberClass() && !Modifier.isStatic(type.getModifiers()))
throw new KryoException("Class cannot be created (non-static member class): " + className(type));
else
throw new KryoException("Class cannot be created (missing no-arg constructor): " + className(type));
else {
StringBuilder errorMessageSb = new StringBuilder("Class cannot be created (missing no-arg constructor): " + className(type));
if (type.getSimpleName().equals("")) {
errorMessageSb.append("\n\tThis is an anonymous class, which is not serializable by default in Kryo. Possible solutions: ")
.append("1. Remove uses of anonymous classes, including double brace initialization, from the containing ")
.append("class. This is the safest solution, as anonymous classes don't have predictable names for serialization.")
.append("\n\t2. Register a FieldSerializer for the containing class and call ")
.append( "FieldSerializer#setIgnoreSyntheticFields(false) on it. This is not safe but may be sufficient temporarily. ")
.append("Use at your own risk.");
}
throw new KryoException(errorMessageSb.toString());
}
}
// InstantiatorStrategy.
return fallbackStrategy.newInstantiatorOf(type);
Expand Down

0 comments on commit 4ac9c4c

Please sign in to comment.