Skip to content

Commit

Permalink
Make Closure public, moving it to ClosureSerializer.
Browse files Browse the repository at this point in the history
Closure is moved to ClosureSerializer because it's tightly coupled
and this makes the connection more obvious.

This also renames `Kryo.isClousre` to `isClosure`, assuming that it
was not used until now it's ignored regarding binary compatibility.

Fixes EsotericSoftware#299, refs EsotericSoftware#215
  • Loading branch information
magro committed Mar 29, 2016
1 parent c10fd76 commit 6c402d9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 5 additions & 0 deletions pom-main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
<className>com/esotericsoftware/reflectasm/**</className>
<differenceType>8001</differenceType>
</difference>
<difference>
<className>com/esotericsoftware/kryo/Kryo</className>
<method>*isClousre*</method>
<differenceType>7002</differenceType>
</difference>
</ignored>
</configuration>
<!-- prevent "clirr-maven-plugin:2.6.1:check failed: Invalid byte tag in constant pool: 18" -->
Expand Down
9 changes: 4 additions & 5 deletions src/com/esotericsoftware/kryo/Kryo.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.TreeMap;
import java.util.TreeSet;

import com.esotericsoftware.kryo.serializers.ClosureSerializer;
import com.esotericsoftware.kryo.serializers.DefaultSerializers.URLSerializer;
import com.esotericsoftware.kryo.serializers.OptionalSerializers;
import com.esotericsoftware.kryo.serializers.GenericsResolver;
Expand Down Expand Up @@ -491,8 +492,8 @@ public Registration getRegistration (Class type) {
registration = getRegistration(type.getEnclosingClass());
} else if (EnumSet.class.isAssignableFrom(type)) {
registration = classResolver.getRegistration(EnumSet.class);
} else if (isClousre(type)) {
registration = classResolver.getRegistration(Closure.class);
} else if (isClosure(type)) {
registration = classResolver.getRegistration(ClosureSerializer.Closure.class);
}
if (registration == null) {
if (registrationRequired) {
Expand Down Expand Up @@ -1174,7 +1175,7 @@ public boolean isFinal (Class type) {
/** Returns true if the specified type is a closure.
* <p>
* This can be overridden to support alternative implementations of clousres. Current version supports Oracle's Java8 only */
public boolean isClousre (Class type) {
protected boolean isClosure(Class type) {
if (type == null) throw new IllegalArgumentException("type cannot be null.");
return type.getName().indexOf('/') >= 0;
}
Expand Down Expand Up @@ -1290,6 +1291,4 @@ public Object newInstance () {
}
}

private static class Closure {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@
* <p>
* <code>
* kryo.register(java.lang.invoke.SerializedLambda.class);<br>
* kryo.register(Closure.class, new ClosureSerializer());</code>
* kryo.register(ClosureSerializer.Closure.class, new ClosureSerializer());</code>
* @author Roman Levenstein <[email protected]> */
public class ClosureSerializer extends Serializer {

/** Marker class to bind ClosureSerializer to. See also {@link Kryo#isClosure(Class)} and {@link Kryo#getRegistration(Class)} */
public static class Closure {
}

private static Method readResolve;
private static Class serializedLambda;
private static Class serializedLambda = java.lang.invoke.SerializedLambda.class;
static {
try {
serializedLambda = Class.forName("java.lang.invoke.SerializedLambda");
readResolve = serializedLambda.getDeclaredMethod("readResolve");
readResolve.setAccessible(true);
} catch (Exception e) {
Expand Down

0 comments on commit 6c402d9

Please sign in to comment.