Browse Source

Merge pull request #273 in CORE/base-third from ~ANDREW ASA/base-third:feature/10.0 to feature/10.0

* commit '012ac2708ae94099a07bb7ca6a697afaf64f54e0':
  KERNEL-1226 去掉core 里面的objenesis,third包里面已经有 & 升级到支持jdk11
research/11.0
andrew asa 5 years ago
parent
commit
a28a01abcb
  1. 4
      fine-kryo/src/com/fr/third/org/objenesis/Objenesis.java
  2. 4
      fine-kryo/src/com/fr/third/org/objenesis/ObjenesisBase.java
  3. 4
      fine-kryo/src/com/fr/third/org/objenesis/ObjenesisException.java
  4. 6
      fine-kryo/src/com/fr/third/org/objenesis/ObjenesisHelper.java
  5. 13
      fine-kryo/src/com/fr/third/org/objenesis/ObjenesisSerializer.java
  6. 15
      fine-kryo/src/com/fr/third/org/objenesis/ObjenesisStd.java
  7. 4
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/ObjectInstantiator.java
  8. 4
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/SerializationInstantiatorHelper.java
  9. 11
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/Android10Instantiator.java
  10. 22
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/Android17Instantiator.java
  11. 24
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/Android18Instantiator.java
  12. 25
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/AndroidSerializationInstantiator.java
  13. 4
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/annotations/Instantiator.java
  14. 4
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/annotations/Typology.java
  15. 7
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/AccessibleInstantiator.java
  16. 6
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ConstructorInstantiator.java
  17. 6
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/FailingInstantiator.java
  18. 13
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/NewInstanceInstantiator.java
  19. 4
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/NullInstantiator.java
  20. 14
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java
  21. 11
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java
  22. 73
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ProxyingInstantiator.java
  23. 15
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiator.java
  24. 17
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiatorBase.java
  25. 9
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/gcj/GCJSerializationInstantiator.java
  26. 13
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/perc/PercInstantiator.java
  27. 28
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/perc/PercSerializationInstantiator.java
  28. 97
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/MagicInstantiator.java
  29. 25
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryHelper.java
  30. 6
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java
  31. 6
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java
  32. 8
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java
  33. 76
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/ClassDefinitionUtils.java
  34. 78
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/ClassUtils.java
  35. 147
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/DefineClassHelper.java
  36. 4
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/UnsafeUtils.java
  37. 4
      fine-kryo/src/com/fr/third/org/objenesis/strategy/BaseInstantiatorStrategy.java
  38. 4
      fine-kryo/src/com/fr/third/org/objenesis/strategy/InstantiatorStrategy.java
  39. 39
      fine-kryo/src/com/fr/third/org/objenesis/strategy/PlatformDescription.java
  40. 18
      fine-kryo/src/com/fr/third/org/objenesis/strategy/SerializingInstantiatorStrategy.java
  41. 12
      fine-kryo/src/com/fr/third/org/objenesis/strategy/SingleInstantiatorStrategy.java
  42. 29
      fine-kryo/src/com/fr/third/org/objenesis/strategy/StdInstantiatorStrategy.java

4
fine-kryo/src/com/fr/third/org/objenesis/Objenesis.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

4
fine-kryo/src/com/fr/third/org/objenesis/ObjenesisBase.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

4
fine-kryo/src/com/fr/third/org/objenesis/ObjenesisException.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

6
fine-kryo/src/com/fr/third/org/objenesis/ObjenesisHelper.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -53,7 +53,7 @@ public final class ObjenesisHelper {
* @return New instance of clazz * @return New instance of clazz
*/ */
public static <T extends Serializable> T newSerializableInstance(Class<T> clazz) { public static <T extends Serializable> T newSerializableInstance(Class<T> clazz) {
return (T) OBJENESIS_SERIALIZER.newInstance(clazz); return OBJENESIS_SERIALIZER.newInstance(clazz);
} }
/** /**

13
fine-kryo/src/com/fr/third/org/objenesis/ObjenesisSerializer.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,7 +15,6 @@
*/ */
package com.fr.third.org.objenesis; package com.fr.third.org.objenesis;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.strategy.SerializingInstantiatorStrategy; import com.fr.third.org.objenesis.strategy.SerializingInstantiatorStrategy;
/** /**
@ -26,17 +25,17 @@ import com.fr.third.org.objenesis.strategy.SerializingInstantiatorStrategy;
public class ObjenesisSerializer extends ObjenesisBase { public class ObjenesisSerializer extends ObjenesisBase {
/** /**
* Default constructor using the {@link SerializingInstantiatorStrategy} * Default constructor using the {@link com.fr.third.org.objenesis.strategy.SerializingInstantiatorStrategy}
*/ */
public ObjenesisSerializer() { public ObjenesisSerializer() {
super(new SerializingInstantiatorStrategy()); super(new SerializingInstantiatorStrategy());
} }
/** /**
* Instance using the {@link SerializingInstantiatorStrategy} with or without caching * Instance using the {@link com.fr.third.org.objenesis.strategy.SerializingInstantiatorStrategy} with or without caching
* {@link ObjectInstantiator}s * {@link com.fr.third.org.objenesis.instantiator.ObjectInstantiator}s
* *
* @param useCache If {@link ObjectInstantiator}s should be cached * @param useCache If {@link com.fr.third.org.objenesis.instantiator.ObjectInstantiator}s should be cached
*/ */
public ObjenesisSerializer(boolean useCache) { public ObjenesisSerializer(boolean useCache) {
super(new SerializingInstantiatorStrategy(), useCache); super(new SerializingInstantiatorStrategy(), useCache);

15
fine-kryo/src/com/fr/third/org/objenesis/ObjenesisStd.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,28 +15,27 @@
*/ */
package com.fr.third.org.objenesis; package com.fr.third.org.objenesis;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.strategy.StdInstantiatorStrategy; import com.fr.third.org.objenesis.strategy.StdInstantiatorStrategy;
/** /**
* Objenesis implementation using the {@link StdInstantiatorStrategy}. * Objenesis implementation using the {@link com.fr.third.org.objenesis.strategy.StdInstantiatorStrategy}.
* *
* @author Henri Tremblay * @author Henri Tremblay
*/ */
public class ObjenesisStd extends ObjenesisBase { public class ObjenesisStd extends ObjenesisBase {
/** /**
* Default constructor using the {@link StdInstantiatorStrategy} * Default constructor using the {@link com.fr.third.org.objenesis.strategy.StdInstantiatorStrategy}
*/ */
public ObjenesisStd() { public ObjenesisStd() {
super(new StdInstantiatorStrategy()); super(new StdInstantiatorStrategy());
} }
/** /**
* Instance using the {@link StdInstantiatorStrategy} with or without * Instance using the {@link com.fr.third.org.objenesis.strategy.StdInstantiatorStrategy} with or without
* caching {@link ObjectInstantiator}s * caching {@link com.fr.third.org.objenesis.instantiator.ObjectInstantiator}s
* *
* @param useCache If {@link ObjectInstantiator}s should be cached * @param useCache If {@link com.fr.third.org.objenesis.instantiator.ObjectInstantiator}s should be cached
*/ */
public ObjenesisStd(boolean useCache) { public ObjenesisStd(boolean useCache) {
super(new StdInstantiatorStrategy(), useCache); super(new StdInstantiatorStrategy(), useCache);

4
fine-kryo/src/com/fr/third/org/objenesis/instantiator/ObjectInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

4
fine-kryo/src/com/fr/third/org/objenesis/instantiator/SerializationInstantiatorHelper.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

11
fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/Android10Instantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,10 +18,10 @@ package com.fr.third.org.objenesis.instantiator.android;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator; import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.ObjenesisException;
/** /**
* Instantiator for Android API level 10 and lover which creates objects without driving their * Instantiator for Android API level 10 and lover which creates objects without driving their
@ -56,10 +56,7 @@ public class Android10Instantiator<T> implements ObjectInstantiator<T> {
newStaticMethod.setAccessible(true); newStaticMethod.setAccessible(true);
return newStaticMethod; return newStaticMethod;
} }
catch(RuntimeException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }

22
fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/Android17Instantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,10 +19,10 @@ import java.io.ObjectStreamClass;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator; import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.ObjenesisException;
/** /**
* Instantiator for Android API level 11 to 17 which creates objects without driving their * Instantiator for Android API level 11 to 17 which creates objects without driving their
@ -58,10 +58,7 @@ public class Android17Instantiator<T> implements ObjectInstantiator<T> {
newInstanceMethod.setAccessible(true); newInstanceMethod.setAccessible(true);
return newInstanceMethod; return newInstanceMethod;
} }
catch(RuntimeException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }
@ -74,16 +71,7 @@ public class Android17Instantiator<T> implements ObjectInstantiator<T> {
return (Integer) newInstanceMethod.invoke(null, Object.class); return (Integer) newInstanceMethod.invoke(null, Object.class);
} }
catch(RuntimeException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e);
}
catch(IllegalAccessException e) {
throw new ObjenesisException(e);
}
catch(InvocationTargetException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }

24
fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/Android18Instantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,13 +19,13 @@ import java.io.ObjectStreamClass;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator; import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.ObjenesisException;
/** /**
* Instantiator for Android API leve 18 and higher. Same as the version 17 but the * Instantiator for Android API level 18 and higher. Same as the version 17 but the
* <code>newInstance</code> now takes a long in parameter * <code>newInstance</code> now takes a long in parameter
* *
* @author Henri Tremblay * @author Henri Tremblay
@ -58,10 +58,7 @@ public class Android18Instantiator<T> implements ObjectInstantiator<T> {
newInstanceMethod.setAccessible(true); newInstanceMethod.setAccessible(true);
return newInstanceMethod; return newInstanceMethod;
} }
catch(RuntimeException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }
@ -74,16 +71,7 @@ public class Android18Instantiator<T> implements ObjectInstantiator<T> {
return (Long) newInstanceMethod.invoke(null, Object.class); return (Long) newInstanceMethod.invoke(null, Object.class);
} }
catch(RuntimeException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e);
}
catch(IllegalAccessException e) {
throw new ObjenesisException(e);
}
catch(InvocationTargetException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }

25
fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/AndroidSerializationInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,10 +19,10 @@ import java.io.ObjectStreamClass;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator; import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.ObjenesisException;
/** /**
* {@link ObjectInstantiator} for Android which creates objects using the constructor from the first * {@link ObjectInstantiator} for Android which creates objects using the constructor from the first
@ -40,7 +40,7 @@ public class AndroidSerializationInstantiator<T> implements ObjectInstantiator<T
public AndroidSerializationInstantiator(Class<T> type) { public AndroidSerializationInstantiator(Class<T> type) {
this.type = type; this.type = type;
newInstanceMethod = getNewInstanceMethod(); newInstanceMethod = getNewInstanceMethod();
Method m = null; Method m;
try { try {
m = ObjectStreamClass.class.getMethod("lookupAny", Class.class); m = ObjectStreamClass.class.getMethod("lookupAny", Class.class);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
@ -48,9 +48,7 @@ public class AndroidSerializationInstantiator<T> implements ObjectInstantiator<T
} }
try { try {
objectStreamClass = (ObjectStreamClass) m.invoke(null, type); objectStreamClass = (ObjectStreamClass) m.invoke(null, type);
} catch (IllegalAccessException e) { } catch (Exception e) {
throw new ObjenesisException(e);
} catch (InvocationTargetException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }
@ -59,13 +57,7 @@ public class AndroidSerializationInstantiator<T> implements ObjectInstantiator<T
try { try {
return type.cast(newInstanceMethod.invoke(objectStreamClass, type)); return type.cast(newInstanceMethod.invoke(objectStreamClass, type));
} }
catch(IllegalAccessException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(IllegalArgumentException e) {
throw new ObjenesisException(e);
}
catch(InvocationTargetException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }
@ -77,10 +69,7 @@ public class AndroidSerializationInstantiator<T> implements ObjectInstantiator<T
newInstanceMethod.setAccessible(true); newInstanceMethod.setAccessible(true);
return newInstanceMethod; return newInstanceMethod;
} }
catch(RuntimeException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }

4
fine-kryo/src/com/fr/third/org/objenesis/instantiator/annotations/Instantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

4
fine-kryo/src/com/fr/third/org/objenesis/instantiator/annotations/Typology.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

7
fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/AccessibleInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,7 +15,6 @@
*/ */
package com.fr.third.org.objenesis.instantiator.basic; package com.fr.third.org.objenesis.instantiator.basic;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
@ -25,7 +24,7 @@ import com.fr.third.org.objenesis.instantiator.annotations.Typology;
* non-public constructors (if the security manager allows it). * non-public constructors (if the security manager allows it).
* *
* @author Joe Walnes * @author Joe Walnes
* @see ObjectInstantiator * @see com.fr.third.org.objenesis.instantiator.ObjectInstantiator
*/ */
@Instantiator(Typology.NOT_COMPLIANT) @Instantiator(Typology.NOT_COMPLIANT)
public class AccessibleInstantiator<T> extends ConstructorInstantiator<T> { public class AccessibleInstantiator<T> extends ConstructorInstantiator<T> {

6
fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ConstructorInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,10 +17,10 @@ package com.fr.third.org.objenesis.instantiator.basic;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator; import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.ObjenesisException;
/** /**
* Instantiates a class by grabbing the no args constructor and calling Constructor.newInstance(). * Instantiates a class by grabbing the no args constructor and calling Constructor.newInstance().

6
fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/FailingInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,10 +15,10 @@
*/ */
package com.fr.third.org.objenesis.instantiator.basic; package com.fr.third.org.objenesis.instantiator.basic;
import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator; import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.ObjenesisException;
/** /**
* The instantiator that always throws an exception. Mainly used for tests * The instantiator that always throws an exception. Mainly used for tests

13
fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/NewInstanceInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,7 +18,7 @@ package com.fr.third.org.objenesis.instantiator.basic;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator; import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.instantiator.util.ClassUtils;
/** /**
* The simplest instantiator - simply calls Class.newInstance(). This can deal with default public * The simplest instantiator - simply calls Class.newInstance(). This can deal with default public
@ -37,12 +37,7 @@ public class NewInstanceInstantiator<T> implements ObjectInstantiator<T> {
} }
public T newInstance() { public T newInstance() {
try { return ClassUtils.newInstance(type);
return type.newInstance();
}
catch(Exception e) {
throw new ObjenesisException(e);
}
} }
} }

4
fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/NullInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

14
fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,10 +25,10 @@ import java.io.ObjectStreamClass;
import java.io.ObjectStreamConstants; import java.io.ObjectStreamConstants;
import java.io.Serializable; import java.io.Serializable;
import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator; import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.ObjenesisException;
/** /**
* Instantiates a class by using a dummy input stream that always feeds data for an empty object of * Instantiates a class by using a dummy input stream that always feeds data for an empty object of
@ -38,7 +38,7 @@ import com.fr.third.org.objenesis.ObjenesisException;
* completely different class. * completely different class.
* *
* @author Leonardo Mesquita * @author Leonardo Mesquita
* @see ObjectInstantiator * @see com.fr.third.org.objenesis.instantiator.ObjectInstantiator
*/ */
@Instantiator(Typology.SERIALIZATION) @Instantiator(Typology.SERIALIZATION)
public class ObjectInputStreamInstantiator<T> implements ObjectInstantiator<T> { public class ObjectInputStreamInstantiator<T> implements ObjectInstantiator<T> {
@ -120,7 +120,7 @@ public class ObjectInputStreamInstantiator<T> implements ObjectInstantiator<T> {
} }
@Override @Override
public int read() throws IOException { public int read() {
int result = data[pointer++]; int result = data[pointer++];
if(pointer >= data.length) { if(pointer >= data.length) {
advanceBuffer(); advanceBuffer();
@ -130,12 +130,12 @@ public class ObjectInputStreamInstantiator<T> implements ObjectInstantiator<T> {
} }
@Override @Override
public int available() throws IOException { public int available() {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
@Override @Override
public int read(byte[] b, int off, int len) throws IOException { public int read(byte[] b, int off, int len) {
int left = len; int left = len;
int remaining = data.length - pointer; int remaining = data.length - pointer;

11
fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,10 +18,10 @@ package com.fr.third.org.objenesis.instantiator.basic;
import java.io.ObjectStreamClass; import java.io.ObjectStreamClass;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator; import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.ObjenesisException;
/** /**
* Instantiates a class by using reflection to make a call to private method * Instantiates a class by using reflection to make a call to private method
@ -44,10 +44,7 @@ public class ObjectStreamClassInstantiator<T> implements ObjectInstantiator<T> {
newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod("newInstance"); newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod("newInstance");
newInstanceMethod.setAccessible(true); newInstanceMethod.setAccessible(true);
} }
catch(RuntimeException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }

73
fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ProxyingInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,11 +19,14 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator; import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.instantiator.util.ClassDefinitionUtils; import com.fr.third.org.objenesis.instantiator.util.ClassDefinitionUtils;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.instantiator.util.ClassUtils;
import static com.fr.third.org.objenesis.instantiator.util.ClassDefinitionUtils.*;
/** /**
* This instantiator creates a class by dynamically extending it. It will skip the call to the parent constructor * This instantiator creates a class by dynamically extending it. It will skip the call to the parent constructor
@ -44,9 +47,9 @@ public class ProxyingInstantiator<T> implements ObjectInstantiator<T> {
private static final int INDEX_UTF8_CLASS = 7; private static final int INDEX_UTF8_CLASS = 7;
private static final int INDEX_UTF8_SUPERCLASS = 8; private static final int INDEX_UTF8_SUPERCLASS = 8;
private static int CONSTANT_POOL_COUNT = 9; private static final int CONSTANT_POOL_COUNT = 9;
private static final byte[] CODE = { ClassDefinitionUtils.OPS_aload_0, ClassDefinitionUtils.OPS_return}; private static final byte[] CODE = { OPS_aload_0, OPS_return};
private static final int CODE_ATTRIBUTE_LENGTH = 12 + CODE.length; private static final int CODE_ATTRIBUTE_LENGTH = 12 + CODE.length;
private static final String SUFFIX = "$$$Objenesis"; private static final String SUFFIX = "$$$Objenesis";
@ -54,28 +57,21 @@ public class ProxyingInstantiator<T> implements ObjectInstantiator<T> {
private static final String CONSTRUCTOR_NAME = "<init>"; private static final String CONSTRUCTOR_NAME = "<init>";
private static final String CONSTRUCTOR_DESC = "()V"; private static final String CONSTRUCTOR_DESC = "()V";
private final Class<?> newType; private final Class<? extends T> newType;
public ProxyingInstantiator(Class<T> type) { public ProxyingInstantiator(Class<T> type) {
byte[] classBytes = writeExtendingClass(type, SUFFIX); byte[] classBytes = writeExtendingClass(type);
try { try {
newType = ClassDefinitionUtils.defineClass(type.getName() + SUFFIX, classBytes, type.getClassLoader()); newType = ClassDefinitionUtils.defineClass(type.getName() + SUFFIX, classBytes, type, type.getClassLoader());
} catch (Exception e) { } catch (Exception e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }
@SuppressWarnings("unchecked")
public T newInstance() { public T newInstance() {
try { return ClassUtils.newInstance(newType);
return (T) newType.newInstance();
} catch (InstantiationException e) {
throw new ObjenesisException(e);
} catch (IllegalAccessException e) {
throw new ObjenesisException(e);
}
} }
/** /**
@ -83,61 +79,58 @@ public class ProxyingInstantiator<T> implements ObjectInstantiator<T> {
* only have an empty default constructor * only have an empty default constructor
* *
* @param type type to extend * @param type type to extend
* @param suffix the suffix appended to the class name to create the next extending class name
* @return the byte for the class * @return the byte for the class
* @throws ObjenesisException is something goes wrong * @throws ObjenesisException is something goes wrong
*/ */
private static byte[] writeExtendingClass(Class<?> type, String suffix) { private static byte[] writeExtendingClass(Class<?> type) {
String parentClazz = ClassDefinitionUtils.classNameToInternalClassName(type.getName()); String parentClazz = ClassUtils.classNameToInternalClassName(type.getName());
String clazz = parentClazz + suffix; String clazz = parentClazz + SUFFIX;
DataOutputStream in = null;
ByteArrayOutputStream bIn = new ByteArrayOutputStream(1000); // 1000 should be large enough to fit the entire class ByteArrayOutputStream bIn = new ByteArrayOutputStream(1000); // 1000 should be large enough to fit the entire class
try { try{
in = new DataOutputStream(bIn); DataOutputStream in = new DataOutputStream(bIn);
in.write(MAGIC);
in.write(ClassDefinitionUtils.MAGIC); in.write(VERSION);
in.write(ClassDefinitionUtils.VERSION);
in.writeShort(CONSTANT_POOL_COUNT); in.writeShort(CONSTANT_POOL_COUNT);
// set all the constant pool here // set all the constant pool here
// 1. class // 1. class
in.writeByte(ClassDefinitionUtils.CONSTANT_Class); in.writeByte(CONSTANT_Class);
in.writeShort(INDEX_UTF8_CLASS); in.writeShort(INDEX_UTF8_CLASS);
// 2. super class // 2. super class
in.writeByte(ClassDefinitionUtils.CONSTANT_Class); in.writeByte(CONSTANT_Class);
in.writeShort(INDEX_UTF8_SUPERCLASS); in.writeShort(INDEX_UTF8_SUPERCLASS);
// 3. default constructor name // 3. default constructor name
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF(CONSTRUCTOR_NAME); in.writeUTF(CONSTRUCTOR_NAME);
// 4. default constructor description // 4. default constructor description
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF(CONSTRUCTOR_DESC); in.writeUTF(CONSTRUCTOR_DESC);
// 5. Code // 5. Code
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF("Code"); in.writeUTF("Code");
// 6. Class name // 6. Class name
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF("L" + clazz + ";"); in.writeUTF("L" + clazz + ";");
// 7. Class name (again) // 7. Class name (again)
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF(clazz); in.writeUTF(clazz);
// 8. Superclass name // 8. Superclass name
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF(parentClazz); in.writeUTF(parentClazz);
// end of constant pool // end of constant pool
// access flags: We want public, ACC_SUPER is always there // access flags: We want public, ACC_SUPER is always there
in.writeShort(ClassDefinitionUtils.ACC_PUBLIC | ClassDefinitionUtils.ACC_SUPER); in.writeShort(ACC_PUBLIC | ACC_SUPER);
// this class index in the constant pool // this class index in the constant pool
in.writeShort(INDEX_CLASS_THIS); in.writeShort(INDEX_CLASS_THIS);
@ -155,7 +148,7 @@ public class ProxyingInstantiator<T> implements ObjectInstantiator<T> {
in.writeShort(1); in.writeShort(1);
// default constructor method_info // default constructor method_info
in.writeShort(ClassDefinitionUtils.ACC_PUBLIC); in.writeShort(ACC_PUBLIC);
in.writeShort(INDEX_UTF8_CONSTRUCTOR_NAME); // index of the method name (<init>) in.writeShort(INDEX_UTF8_CONSTRUCTOR_NAME); // index of the method name (<init>)
in.writeShort(INDEX_UTF8_CONSTRUCTOR_DESC); // index of the description in.writeShort(INDEX_UTF8_CONSTRUCTOR_DESC); // index of the description
in.writeShort(1); // number of attributes: only one, the code in.writeShort(1); // number of attributes: only one, the code
@ -176,14 +169,6 @@ public class ProxyingInstantiator<T> implements ObjectInstantiator<T> {
} catch (IOException e) { } catch (IOException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} finally {
if(in != null) {
try {
in.close();
} catch (IOException e) {
throw new ObjenesisException(e);
}
}
} }
return bIn.toByteArray(); return bIn.toByteArray();

15
fine-kryo/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,7 +17,6 @@ package com.fr.third.org.objenesis.instantiator.gcj;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
@ -27,7 +26,7 @@ import com.fr.third.org.objenesis.instantiator.annotations.Typology;
* work on GCJ JVMs. This instantiator will not call any constructors. * work on GCJ JVMs. This instantiator will not call any constructors.
* *
* @author Leonardo Mesquita * @author Leonardo Mesquita
* @see ObjectInstantiator * @see com.fr.third.org.objenesis.instantiator.ObjectInstantiator
*/ */
@Instantiator(Typology.STANDARD) @Instantiator(Typology.STANDARD)
public class GCJInstantiator<T> extends GCJInstantiatorBase<T> { public class GCJInstantiator<T> extends GCJInstantiatorBase<T> {
@ -40,13 +39,7 @@ public class GCJInstantiator<T> extends GCJInstantiatorBase<T> {
try { try {
return type.cast(newObjectMethod.invoke(dummyStream, type, Object.class)); return type.cast(newObjectMethod.invoke(dummyStream, type, Object.class));
} }
catch(RuntimeException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(IllegalAccessException e) {
throw new ObjenesisException(e);
}
catch(InvocationTargetException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }

17
fine-kryo/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiatorBase.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,8 +19,8 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
/** /**
* Base class for GCJ-based instantiators. It initializes reflection access to method * Base class for GCJ-based instantiators. It initializes reflection access to method
@ -41,18 +41,11 @@ public abstract class GCJInstantiatorBase<T> implements ObjectInstantiator<T> {
private static void initialize() { private static void initialize() {
if(newObjectMethod == null) { if(newObjectMethod == null) {
try { try {
newObjectMethod = ObjectInputStream.class.getDeclaredMethod("newObject", new Class[] { newObjectMethod = ObjectInputStream.class.getDeclaredMethod("newObject", Class.class, Class.class);
Class.class, Class.class});
newObjectMethod.setAccessible(true); newObjectMethod.setAccessible(true);
dummyStream = new DummyStream(); dummyStream = new DummyStream();
} }
catch(RuntimeException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e);
}
catch(IOException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }

9
fine-kryo/src/com/fr/third/org/objenesis/instantiator/gcj/GCJSerializationInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,7 +15,6 @@
*/ */
package com.fr.third.org.objenesis.instantiator.gcj; package com.fr.third.org.objenesis.instantiator.gcj;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.SerializationInstantiatorHelper; import com.fr.third.org.objenesis.instantiator.SerializationInstantiatorHelper;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
@ -27,11 +26,11 @@ import com.fr.third.org.objenesis.instantiator.annotations.Typology;
* calling the first non-serializable superclass' no-arg constructor. * calling the first non-serializable superclass' no-arg constructor.
* *
* @author Leonardo Mesquita * @author Leonardo Mesquita
* @see ObjectInstantiator * @see com.fr.third.org.objenesis.instantiator.ObjectInstantiator
*/ */
@Instantiator(Typology.SERIALIZATION) @Instantiator(Typology.SERIALIZATION)
public class GCJSerializationInstantiator<T> extends GCJInstantiatorBase<T> { public class GCJSerializationInstantiator<T> extends GCJInstantiatorBase<T> {
private Class<? super T> superType; private final Class<? super T> superType;
public GCJSerializationInstantiator(Class<T> type) { public GCJSerializationInstantiator(Class<T> type) {
super(type); super(type);

13
fine-kryo/src/com/fr/third/org/objenesis/instantiator/perc/PercInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,8 +18,8 @@ package com.fr.third.org.objenesis.instantiator.perc;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
@ -29,7 +29,7 @@ import com.fr.third.org.objenesis.instantiator.annotations.Typology;
* Aonix Perc support team. * Aonix Perc support team.
* *
* @author Henri Tremblay * @author Henri Tremblay
* @see ObjectInstantiator * @see com.fr.third.org.objenesis.instantiator.ObjectInstantiator
*/ */
@Instantiator(Typology.STANDARD) @Instantiator(Typology.STANDARD)
public class PercInstantiator<T> implements ObjectInstantiator<T> { public class PercInstantiator<T> implements ObjectInstantiator<T> {
@ -47,10 +47,7 @@ public class PercInstantiator<T> implements ObjectInstantiator<T> {
Boolean.TYPE); Boolean.TYPE);
newInstanceMethod.setAccessible(true); newInstanceMethod.setAccessible(true);
} }
catch(RuntimeException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }

28
fine-kryo/src/com/fr/third/org/objenesis/instantiator/perc/PercSerializationInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,8 +20,8 @@ import java.io.Serializable;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
@ -33,7 +33,7 @@ import com.fr.third.org.objenesis.instantiator.annotations.Typology;
* Based on code provided by Aonix but <b>doesn't work right now</b> * Based on code provided by Aonix but <b>doesn't work right now</b>
* *
* @author Henri Tremblay * @author Henri Tremblay
* @see ObjectInstantiator * @see com.fr.third.org.objenesis.instantiator.ObjectInstantiator
*/ */
@Instantiator(Typology.SERIALIZATION) @Instantiator(Typology.SERIALIZATION)
public class PercSerializationInstantiator<T> implements ObjectInstantiator<T> { public class PercSerializationInstantiator<T> implements ObjectInstantiator<T> {
@ -56,7 +56,7 @@ public class PercSerializationInstantiator<T> implements ObjectInstantiator<T> {
Class<?> percMethodClass = Class.forName("COM.newmonics.PercClassLoader.Method"); Class<?> percMethodClass = Class.forName("COM.newmonics.PercClassLoader.Method");
newInstanceMethod = ObjectInputStream.class.getDeclaredMethod("noArgConstruct", newInstanceMethod = ObjectInputStream.class.getDeclaredMethod("noArgConstruct",
new Class[] {Class.class, Object.class, percMethodClass}); Class.class, Object.class, percMethodClass);
newInstanceMethod.setAccessible(true); newInstanceMethod.setAccessible(true);
// Create invoke params // Create invoke params
@ -64,22 +64,13 @@ public class PercSerializationInstantiator<T> implements ObjectInstantiator<T> {
Method getPercClassMethod = percClassClass.getDeclaredMethod("getPercClass", Class.class); Method getPercClassMethod = percClassClass.getDeclaredMethod("getPercClass", Class.class);
Object someObject = getPercClassMethod.invoke(null, unserializableType); Object someObject = getPercClassMethod.invoke(null, unserializableType);
Method findMethodMethod = someObject.getClass().getDeclaredMethod("findMethod", Method findMethodMethod = someObject.getClass().getDeclaredMethod("findMethod",
new Class[] {String.class}); String.class);
Object percMethod = findMethodMethod.invoke(someObject, "<init>()V"); Object percMethod = findMethodMethod.invoke(someObject, "<init>()V");
typeArgs = new Object[] {unserializableType, type, percMethod}; typeArgs = new Object[] {unserializableType, type, percMethod};
} }
catch(ClassNotFoundException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e);
}
catch(InvocationTargetException e) {
throw new ObjenesisException(e);
}
catch(IllegalAccessException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }
@ -89,10 +80,7 @@ public class PercSerializationInstantiator<T> implements ObjectInstantiator<T> {
try { try {
return (T) newInstanceMethod.invoke(null, typeArgs); return (T) newInstanceMethod.invoke(null, typeArgs);
} }
catch(IllegalAccessException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(InvocationTargetException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }

97
fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/MagicInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,11 +19,14 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.util.ClassDefinitionUtils;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.instantiator.util.ClassDefinitionUtils;
import com.fr.third.org.objenesis.instantiator.util.ClassUtils;
import static com.fr.third.org.objenesis.instantiator.util.ClassDefinitionUtils.*;
/** /**
* This instantiator will correctly bypass the constructors by instantiating the class using the default * This instantiator will correctly bypass the constructors by instantiating the class using the default
@ -55,18 +58,18 @@ public class MagicInstantiator<T> implements ObjectInstantiator<T> {
private static final int INDEX_CLASS_TYPE = 17; private static final int INDEX_CLASS_TYPE = 17;
private static final int INDEX_UTF8_TYPE = 18; private static final int INDEX_UTF8_TYPE = 18;
private static int CONSTANT_POOL_COUNT = 19; private static final int CONSTANT_POOL_COUNT = 19;
private static final byte[] CONSTRUCTOR_CODE = { ClassDefinitionUtils.OPS_aload_0, ClassDefinitionUtils.OPS_invokespecial, 0, INDEX_METHODREF_OBJECT_CONSTRUCTOR, ClassDefinitionUtils.OPS_return}; private static final byte[] CONSTRUCTOR_CODE = { OPS_aload_0, OPS_invokespecial, 0, INDEX_METHODREF_OBJECT_CONSTRUCTOR, OPS_return};
private static final int CONSTRUCTOR_CODE_ATTRIBUTE_LENGTH = 12 + CONSTRUCTOR_CODE.length; private static final int CONSTRUCTOR_CODE_ATTRIBUTE_LENGTH = 12 + CONSTRUCTOR_CODE.length;
private static final byte[] NEWINSTANCE_CODE = { ClassDefinitionUtils.OPS_new, 0, INDEX_CLASS_TYPE, ClassDefinitionUtils.OPS_dup, ClassDefinitionUtils.OPS_invokespecial, 0, INDEX_METHODREF_OBJECT_CONSTRUCTOR, ClassDefinitionUtils.OPS_areturn}; private static final byte[] NEWINSTANCE_CODE = { OPS_new, 0, INDEX_CLASS_TYPE, OPS_dup, OPS_invokespecial, 0, INDEX_METHODREF_OBJECT_CONSTRUCTOR, OPS_areturn};
private static final int NEWINSTANCE_CODE_ATTRIBUTE_LENGTH = 12 + NEWINSTANCE_CODE.length; private static final int NEWINSTANCE_CODE_ATTRIBUTE_LENGTH = 12 + NEWINSTANCE_CODE.length;
private static final String CONSTRUCTOR_NAME = "<init>"; private static final String CONSTRUCTOR_NAME = "<init>";
private static final String CONSTRUCTOR_DESC = "()V"; private static final String CONSTRUCTOR_DESC = "()V";
private ObjectInstantiator<T> instantiator; private final ObjectInstantiator<T> instantiator;
public MagicInstantiator(Class<T> type) { public MagicInstantiator(Class<T> type) {
instantiator = newInstantiatorOf(type); instantiator = newInstantiatorOf(type);
@ -85,29 +88,23 @@ public class MagicInstantiator<T> implements ObjectInstantiator<T> {
return instantiator; return instantiator;
} }
private <T> ObjectInstantiator<T> newInstantiatorOf(Class<T> type) { private ObjectInstantiator<T> newInstantiatorOf(Class<T> type) {
String suffix = type.getSimpleName(); String suffix = type.getSimpleName();
String className = getClass().getName() + "$$$" + suffix; String className = getClass().getName() + "$$$" + suffix;
Class<ObjectInstantiator<T>> clazz = ClassDefinitionUtils.getExistingClass(getClass().getClassLoader(), className); Class<ObjectInstantiator<T>> clazz = ClassUtils.getExistingClass(getClass().getClassLoader(), className);
if(clazz == null) { if(clazz == null) {
byte[] classBytes = writeExtendingClass(type, className); byte[] classBytes = writeExtendingClass(type, className);
try { try {
clazz = ClassDefinitionUtils.defineClass(className, classBytes, getClass().getClassLoader()); clazz = ClassDefinitionUtils.defineClass(className, classBytes, type, getClass().getClassLoader());
} catch (Exception e) { } catch (Exception e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }
try { return ClassUtils.newInstance(clazz);
return clazz.newInstance();
} catch (InstantiationException e) {
throw new ObjenesisException(e);
} catch (IllegalAccessException e) {
throw new ObjenesisException(e);
}
} }
/** /**
@ -120,98 +117,96 @@ public class MagicInstantiator<T> implements ObjectInstantiator<T> {
* @throws ObjenesisException is something goes wrong * @throws ObjenesisException is something goes wrong
*/ */
private byte[] writeExtendingClass(Class<?> type, String className) { private byte[] writeExtendingClass(Class<?> type, String className) {
String clazz = ClassDefinitionUtils.classNameToInternalClassName(className); String clazz = ClassUtils.classNameToInternalClassName(className);
DataOutputStream in = null;
ByteArrayOutputStream bIn = new ByteArrayOutputStream(1000); // 1000 should be large enough to fit the entire class ByteArrayOutputStream bIn = new ByteArrayOutputStream(1000); // 1000 should be large enough to fit the entire class
try { try{
in = new DataOutputStream(bIn); DataOutputStream in = new DataOutputStream(bIn);
in.write(MAGIC);
in.write(ClassDefinitionUtils.MAGIC); in.write(VERSION);
in.write(ClassDefinitionUtils.VERSION);
in.writeShort(CONSTANT_POOL_COUNT); in.writeShort(CONSTANT_POOL_COUNT);
// set all the constant pool here // set all the constant pool here
// 1. class // 1. class
in.writeByte(ClassDefinitionUtils.CONSTANT_Class); in.writeByte(CONSTANT_Class);
in.writeShort(INDEX_UTF8_INSTANTIATOR_CLASS); in.writeShort(INDEX_UTF8_INSTANTIATOR_CLASS);
// 2. super class // 2. super class
in.writeByte(ClassDefinitionUtils.CONSTANT_Class); in.writeByte(CONSTANT_Class);
in.writeShort(INDEX_UTF8_SUPERCLASS); in.writeShort(INDEX_UTF8_SUPERCLASS);
// 3. default constructor name // 3. default constructor name
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF(CONSTRUCTOR_NAME); in.writeUTF(CONSTRUCTOR_NAME);
// 4. default constructor description // 4. default constructor description
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF(CONSTRUCTOR_DESC); in.writeUTF(CONSTRUCTOR_DESC);
// 5. Code // 5. Code
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF("Code"); in.writeUTF("Code");
// 6. Class name // 6. Class name
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF("L" + clazz + ";"); in.writeUTF("L" + clazz + ";");
// 7. Class name (again) // 7. Class name (again)
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF(clazz); in.writeUTF(clazz);
// 8. Superclass name // 8. Superclass name
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
// in.writeUTF("java/lang/Object"); // in.writeUTF("java/lang/Object");
in.writeUTF(MAGIC_ACCESSOR); in.writeUTF(MAGIC_ACCESSOR);
// 9. ObjectInstantiator interface // 9. ObjectInstantiator interface
in.writeByte(ClassDefinitionUtils.CONSTANT_Class); in.writeByte(CONSTANT_Class);
in.writeShort(INDEX_UTF8_INTERFACE); in.writeShort(INDEX_UTF8_INTERFACE);
// 10. ObjectInstantiator name // 10. ObjectInstantiator name
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF(ObjectInstantiator.class.getName().replace('.', '/')); in.writeUTF(ObjectInstantiator.class.getName().replace('.', '/'));
// 11. newInstance name // 11. newInstance name
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF("newInstance"); in.writeUTF("newInstance");
// 12. newInstance desc // 12. newInstance desc
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF("()Ljava/lang/Object;"); in.writeUTF("()Ljava/lang/Object;");
// 13. Methodref to the Object constructor // 13. Methodref to the Object constructor
in.writeByte(ClassDefinitionUtils.CONSTANT_Methodref); in.writeByte(CONSTANT_Methodref);
in.writeShort(INDEX_CLASS_OBJECT); in.writeShort(INDEX_CLASS_OBJECT);
in.writeShort(INDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTOR); in.writeShort(INDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTOR);
// 14. Object class // 14. Object class
in.writeByte(ClassDefinitionUtils.CONSTANT_Class); in.writeByte(CONSTANT_Class);
in.writeShort(INDEX_UTF8_OBJECT); in.writeShort(INDEX_UTF8_OBJECT);
// 15. Object class name // 15. Object class name
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF("java/lang/Object"); in.writeUTF("java/lang/Object");
// 16. Default constructor name and type // 16. Default constructor name and type
in.writeByte(ClassDefinitionUtils.CONSTANT_NameAndType); in.writeByte(CONSTANT_NameAndType);
in.writeShort(INDEX_UTF8_CONSTRUCTOR_NAME); in.writeShort(INDEX_UTF8_CONSTRUCTOR_NAME);
in.writeShort(INDEX_UTF8_CONSTRUCTOR_DESC); in.writeShort(INDEX_UTF8_CONSTRUCTOR_DESC);
// 17. Type to instantiate class // 17. Type to instantiate class
in.writeByte(ClassDefinitionUtils.CONSTANT_Class); in.writeByte(CONSTANT_Class);
in.writeShort(INDEX_UTF8_TYPE); in.writeShort(INDEX_UTF8_TYPE);
// 18. Type to instantiate name // 18. Type to instantiate name
in.writeByte(ClassDefinitionUtils.CONSTANT_Utf8); in.writeByte(CONSTANT_Utf8);
in.writeUTF(ClassDefinitionUtils.classNameToInternalClassName(type.getName())); in.writeUTF(ClassUtils.classNameToInternalClassName(type.getName()));
// end of constant pool // end of constant pool
// access flags: We want public, ACC_SUPER is always there // access flags: We want public, ACC_SUPER is always there
in.writeShort(ClassDefinitionUtils.ACC_PUBLIC | ClassDefinitionUtils.ACC_SUPER | ClassDefinitionUtils.ACC_FINAL); in.writeShort(ACC_PUBLIC | ACC_SUPER | ACC_FINAL);
// this class index in the constant pool // this class index in the constant pool
in.writeShort(INDEX_CLASS_THIS); in.writeShort(INDEX_CLASS_THIS);
@ -230,7 +225,7 @@ public class MagicInstantiator<T> implements ObjectInstantiator<T> {
in.writeShort(2); in.writeShort(2);
// default constructor method_info // default constructor method_info
in.writeShort(ClassDefinitionUtils.ACC_PUBLIC); in.writeShort(ACC_PUBLIC);
in.writeShort(INDEX_UTF8_CONSTRUCTOR_NAME); // index of the method name (<init>) in.writeShort(INDEX_UTF8_CONSTRUCTOR_NAME); // index of the method name (<init>)
in.writeShort(INDEX_UTF8_CONSTRUCTOR_DESC); // index of the description in.writeShort(INDEX_UTF8_CONSTRUCTOR_DESC); // index of the description
in.writeShort(1); // number of attributes: only one, the code in.writeShort(1); // number of attributes: only one, the code
@ -246,7 +241,7 @@ public class MagicInstantiator<T> implements ObjectInstantiator<T> {
in.writeShort(0); // attributes count = 0, no need to have LineNumberTable and LocalVariableTable in.writeShort(0); // attributes count = 0, no need to have LineNumberTable and LocalVariableTable
// newInstance method_info // newInstance method_info
in.writeShort(ClassDefinitionUtils.ACC_PUBLIC); in.writeShort(ACC_PUBLIC);
in.writeShort(INDEX_UTF8_NEWINSTANCE_NAME); // index of the method name (newInstance) in.writeShort(INDEX_UTF8_NEWINSTANCE_NAME); // index of the method name (newInstance)
in.writeShort(INDEX_UTF8_NEWINSTANCE_DESC); // index of the description in.writeShort(INDEX_UTF8_NEWINSTANCE_DESC); // index of the description
in.writeShort(1); // number of attributes: only one, the code in.writeShort(1); // number of attributes: only one, the code
@ -266,14 +261,6 @@ public class MagicInstantiator<T> implements ObjectInstantiator<T> {
} catch (IOException e) { } catch (IOException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} finally {
if(in != null) {
try {
in.close();
} catch (IOException e) {
throw new ObjenesisException(e);
}
}
} }
return bIn.toByteArray(); return bIn.toByteArray();

25
fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryHelper.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,8 +18,8 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
/** /**
@ -44,13 +44,7 @@ class SunReflectionFactoryHelper {
return (Constructor<T>) newConstructorForSerializationMethod.invoke( return (Constructor<T>) newConstructorForSerializationMethod.invoke(
reflectionFactory, type, constructor); reflectionFactory, type, constructor);
} }
catch(IllegalArgumentException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(IllegalAccessException e) {
throw new ObjenesisException(e);
}
catch(InvocationTargetException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }
@ -70,16 +64,7 @@ class SunReflectionFactoryHelper {
"getReflectionFactory"); "getReflectionFactory");
return method.invoke(null); return method.invoke(null);
} }
catch(NoSuchMethodException e) { catch(Exception e) {
throw new ObjenesisException(e);
}
catch(IllegalAccessException e) {
throw new ObjenesisException(e);
}
catch(IllegalArgumentException e) {
throw new ObjenesisException(e);
}
catch(InvocationTargetException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }

6
fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,8 +17,8 @@ package com.fr.third.org.objenesis.instantiator.sun;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;

6
fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,8 +18,8 @@ package com.fr.third.org.objenesis.instantiator.sun;
import java.io.NotSerializableException; import java.io.NotSerializableException;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.SerializationInstantiatorHelper; import com.fr.third.org.objenesis.instantiator.SerializationInstantiatorHelper;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;

8
fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,12 +15,12 @@
*/ */
package com.fr.third.org.objenesis.instantiator.sun; package com.fr.third.org.objenesis.instantiator.sun;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.util.UnsafeUtils;
import sun.misc.Unsafe; import sun.misc.Unsafe;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator; import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology; import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.instantiator.util.UnsafeUtils;
/** /**
* Instantiates an object, WITHOUT calling it's constructor, using * Instantiates an object, WITHOUT calling it's constructor, using

76
fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/ClassDefinitionUtils.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -67,15 +67,11 @@ public final class ClassDefinitionUtils {
private ClassDefinitionUtils() { } private ClassDefinitionUtils() { }
// private static Method DEFINE_CLASS;
private static final ProtectionDomain PROTECTION_DOMAIN; private static final ProtectionDomain PROTECTION_DOMAIN;
static { static {
PROTECTION_DOMAIN = AccessController.doPrivileged(new PrivilegedAction<ProtectionDomain>() {
public ProtectionDomain run() { PROTECTION_DOMAIN = AccessController.doPrivileged((PrivilegedAction<ProtectionDomain>) ClassDefinitionUtils.class.getProtectionDomain());
return ClassDefinitionUtils.class.getProtectionDomain();
}
});
} }
/** /**
@ -83,16 +79,17 @@ public final class ClassDefinitionUtils {
* <code>ReflectUtils.defineClass</code> * <code>ReflectUtils.defineClass</code>
* *
* @param <T> type of the class returned * @param <T> type of the class returned
* @param className class name in the format <code>org.objenesis.MyClass</code> * @param className class name in the format <code>com.fr.third.org.objenesis.MyClass</code>
* @param b bytes representing the class * @param b bytes representing the class
* @param neighbor a class in the same package as the loaded class
* @param loader the class loader where the class will be loaded * @param loader the class loader where the class will be loaded
* @return the newly loaded class * @return the newly loaded class
* @throws Exception whenever something goes wrong * @throws Exception whenever something goes wrong
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> Class<T> defineClass(String className, byte[] b, ClassLoader loader) public static <T> Class<T> defineClass(String className, byte[] b, Class<?> neighbor, ClassLoader loader)
throws Exception { throws Exception {
Class<T> c = (Class<T>) UnsafeUtils.getUnsafe().defineClass(className, b, 0, b.length, loader, PROTECTION_DOMAIN); Class<T> c = (Class<T>) DefineClassHelper.defineClass(className, b, 0, b.length, neighbor, loader, PROTECTION_DOMAIN);
// Force static initializers to run. // Force static initializers to run.
Class.forName(className, true, loader); Class.forName(className, true, loader);
return c; return c;
@ -108,18 +105,17 @@ public final class ClassDefinitionUtils {
*/ */
public static byte[] readClass(String className) throws IOException { public static byte[] readClass(String className) throws IOException {
// convert to a resource // convert to a resource
className = classNameToResource(className); className = ClassUtils.classNameToResource(className);
byte[] b = new byte[2500]; // I'm assuming that I'm reading class that are not too big byte[] b = new byte[2500]; // I'm assuming that I'm reading class that are not too big
int length; int length=0;
InputStream in = ClassDefinitionUtils.class.getClassLoader().getResourceAsStream(className);
try { try {
InputStream in = ClassDefinitionUtils.class.getClassLoader().getResourceAsStream(className);
length = in.read(b); length = in.read(b);
} } catch (Exception e) {
finally {
in.close();
} }
if(length >= 2500) { if(length >= 2500) {
@ -139,52 +135,12 @@ public final class ClassDefinitionUtils {
* @throws IOException if we fail to write the class * @throws IOException if we fail to write the class
*/ */
public static void writeClass(String fileName, byte[] bytes) throws IOException { public static void writeClass(String fileName, byte[] bytes) throws IOException {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
try { try {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
out.write(bytes); out.write(bytes);
} } catch (Throwable e) {
finally {
out.close();
}
}
/**
* Will convert a class name to its name in the class definition format (e.g {@code org.objenesis.EmptyClass}
* becomes {@code org/objenesis/EmptyClass})
*
* @param className full class name including the package
* @return the internal name
*/
public static String classNameToInternalClassName(String className) {
return className.replace('.', '/');
}
/**
* Will convert a class name to its class loader resource name (e.g {@code org.objenesis.EmptyClass}
* becomes {@code org/objenesis/EmptyClass.class})
*
* @param className full class name including the package
* @return the resource name
*/
public static String classNameToResource(String className) {
return classNameToInternalClassName(className) + ".class";
}
/**
* Check if this class already exists in the class loader and return it if it does
*
* @param <T> type of the class returned
* @param classLoader Class loader where to search the class
* @param className Class name with full path
* @return the class if it already exists or null
*/
@SuppressWarnings("unchecked")
public static <T> Class<T> getExistingClass(ClassLoader classLoader, String className) {
try {
return (Class<T>) Class.forName(className, true, classLoader);
}
catch (ClassNotFoundException e) {
return null;
} }
} }
} }

78
fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/ClassUtils.java

@ -0,0 +1,78 @@
/*
* Copyright 2006-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fr.third.org.objenesis.instantiator.util;
import com.fr.third.org.objenesis.ObjenesisException;
/**
* Helper class for to play with classes. It contains everything needed to play with a class
* except the dodgy (Java 8) code you will find in {@link ClassDefinitionUtils}.
*
* @author Henri Tremblay
*/
public final class ClassUtils {
private ClassUtils() { }
/**
* Will convert a class name to its name in the class definition format (e.g {@code com.fr.third.org.objenesis.EmptyClass}
* becomes {@code org/objenesis/EmptyClass})
*
* @param className full class name including the package
* @return the internal name
*/
public static String classNameToInternalClassName(String className) {
return className.replace('.', '/');
}
/**
* Will convert a class name to its class loader resource name (e.g {@code com.fr.third.org.objenesis.EmptyClass}
* becomes {@code org/objenesis/EmptyClass.class})
*
* @param className full class name including the package
* @return the resource name
*/
public static String classNameToResource(String className) {
return classNameToInternalClassName(className) + ".class";
}
/**
* Check if this class already exists in the class loader and return it if it does
*
* @param <T> type of the class returned
* @param classLoader Class loader where to search the class
* @param className Class name with full path
* @return the class if it already exists or null
*/
@SuppressWarnings("unchecked")
public static <T> Class<T> getExistingClass(ClassLoader classLoader, String className) {
try {
return (Class<T>) Class.forName(className, true, classLoader);
}
catch (ClassNotFoundException e) {
return null;
}
}
@SuppressWarnings("deprecation")
public static <T> T newInstance(Class<T> clazz) {
try {
return clazz.newInstance();
} catch (Exception e) {
throw new ObjenesisException(e);
}
}
}

147
fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/DefineClassHelper.java

@ -0,0 +1,147 @@
/*
* Copyright 2006-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fr.third.org.objenesis.instantiator.util;
import sun.misc.Unsafe;
import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.strategy.PlatformDescription;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.security.ProtectionDomain;
/**
* Java 11+ removed sun.misc.Unsafe.defineClass. This class bridges the gap to work from Java 1.8 up to 11.
* <p>
* It was inspired from <a href="https://github.com/jboss-javassist/javassist/blob/master/src/main/javassist/util/proxy/DefineClassHelper.java">javassist</a>.
*
* @author Henri Tremblay
*/
public final class DefineClassHelper {
private static abstract class Helper {
abstract Class<?> defineClass(String name, byte[] b, int off, int len, Class<?> neighbor,
ClassLoader loader, ProtectionDomain protectionDomain);
}
private static class Java8 extends Helper {
private final MethodHandle defineClass = defineClass();
private MethodHandle defineClass() {
MethodType mt = MethodType.methodType(Class.class, String.class, byte[].class, int.class, int.class, ClassLoader.class, ProtectionDomain.class);
MethodHandle m;
try {
m = MethodHandles.publicLookup().findVirtual(Unsafe.class, "defineClass", mt);
} catch(Exception e) {
throw new ObjenesisException(e);
}
Unsafe unsafe = UnsafeUtils.getUnsafe();
return m.bindTo(unsafe);
}
@Override
Class<?> defineClass(String className, byte[] b, int off, int len, Class<?> neighbor, ClassLoader loader, ProtectionDomain protectionDomain) {
try {
return (Class<?>) defineClass.invokeExact(className, b, off, len, loader, protectionDomain);
} catch (Throwable e) {
if(e instanceof Error) {
throw (Error) e;
}
if(e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new ObjenesisException(e);
}
}
}
private static class Java11 extends Helper {
private final Class<?> module = module();
private final MethodHandles.Lookup lookup = MethodHandles.lookup();
private final MethodHandle getModule = getModule();
private final MethodHandle addReads = addReads();
private final MethodHandle privateLookupIn = privateLookupIn();
private final MethodHandle defineClass = defineClass();
private Class<?> module() {
try {
return Class.forName("java.lang.Module");
} catch (ClassNotFoundException e) {
throw new ObjenesisException(e);
}
}
private MethodHandle getModule() {
try {
return lookup.findVirtual(Class.class, "getModule", MethodType.methodType(module));
} catch (Exception e) {
throw new ObjenesisException(e);
}
}
private MethodHandle addReads() {
try {
return lookup.findVirtual(module, "addReads", MethodType.methodType(module, module));
} catch (Exception e) {
throw new ObjenesisException(e);
}
}
private MethodHandle privateLookupIn() {
try {
return lookup.findStatic(MethodHandles.class, "privateLookupIn", MethodType.methodType(MethodHandles.Lookup.class, Class.class, MethodHandles.Lookup.class));
} catch (Exception e) {
throw new ObjenesisException(e);
}
}
private MethodHandle defineClass() {
try {
return lookup.findVirtual(MethodHandles.Lookup.class, "defineClass", MethodType.methodType(Class.class, byte[].class));
} catch (Exception e) {
throw new ObjenesisException(e);
}
}
@Override
Class<?> defineClass(String className, byte[] b, int off, int len, Class<?> neighbor, ClassLoader loader, ProtectionDomain protectionDomain) {
try {
Object module = getModule.invokeWithArguments(DefineClassHelper.class);
Object neighborModule = getModule.invokeWithArguments(neighbor);
addReads.invokeWithArguments(module, neighborModule);
MethodHandles.Lookup prvlookup = (MethodHandles.Lookup) privateLookupIn.invokeExact(neighbor, lookup);
return (Class<?>) defineClass.invokeExact(prvlookup, b);
} catch (Throwable e) {
throw new ObjenesisException(neighbor.getName() + " has no permission to define the class", e);
}
}
}
// Java 11+ removed sun.misc.Unsafe.defineClass, so we fallback to invoking defineClass on
// ClassLoader until we have an implementation that uses MethodHandles.Lookup.defineClass
private static final Helper privileged = PlatformDescription.isAfterJava11() ?
new Java11() : new Java8();
public static Class<?> defineClass(String name, byte[] b, int off, int len, Class<?> neighbor,
ClassLoader loader, ProtectionDomain protectionDomain) {
return privileged.defineClass(name, b, off, len, neighbor, loader, protectionDomain);
}
private DefineClassHelper() {}
}

4
fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/UnsafeUtils.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

4
fine-kryo/src/com/fr/third/org/objenesis/strategy/BaseInstantiatorStrategy.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

4
fine-kryo/src/com/fr/third/org/objenesis/strategy/InstantiatorStrategy.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

39
fine-kryo/src/com/fr/third/org/objenesis/strategy/PlatformDescription.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,10 +15,10 @@
*/ */
package com.fr.third.org.objenesis.strategy; package com.fr.third.org.objenesis.strategy;
import com.fr.third.org.objenesis.ObjenesisException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import com.fr.third.org.objenesis.ObjenesisException;
/** /**
* List of constants describing the currently used platform. * List of constants describing the currently used platform.
* *
@ -26,9 +26,6 @@ import java.lang.reflect.Field;
*/ */
public final class PlatformDescription { public final class PlatformDescription {
/** JVM_NAME prefix for JRockit */
public static final String JROCKIT = "BEA";
/** JVM_NAME prefix for GCJ */ /** JVM_NAME prefix for GCJ */
public static final String GNU = "GNU libgcj"; public static final String GNU = "GNU libgcj";
@ -93,9 +90,8 @@ public final class PlatformDescription {
+ "JVM version=" + VM_VERSION + ", " + "JVM version=" + VM_VERSION + ", "
+ "JVM info=" + VM_INFO; + "JVM info=" + VM_INFO;
// Add the API level is it's an Android platform // Add the API level if it's an Android platform
int androidVersion = ANDROID_VERSION; if(ANDROID_VERSION != 0) {
if(androidVersion != 0) {
desc += ", API level=" + ANDROID_VERSION; desc += ", API level=" + ANDROID_VERSION;
} }
desc += ")"; desc += ")";
@ -134,6 +130,29 @@ public final class PlatformDescription {
return bootClasspath != null && bootClasspath.toLowerCase().contains("core-oj.jar"); return bootClasspath != null && bootClasspath.toLowerCase().contains("core-oj.jar");
} }
/**
* Tells if the current JVM is running Java 9 or above
*
* @return if the current JVM is Java 9 or above
*/
public static boolean isAfterJigsaw() {
String version = PlatformDescription.SPECIFICATION_VERSION;
return version.indexOf('.') < 0; // No dot means the version is 9, 10, 11, ... not 1.6, 1.7, 1.8
}
/**
* Tells if the current JVM is running Java 11 or above
*
* @return if the current JVM is Java 11 or above
*/
public static boolean isAfterJava11() {
if(!isAfterJigsaw()) {
return false;
}
int version = Integer.parseInt(PlatformDescription.SPECIFICATION_VERSION);
return version >= 11;
}
public static boolean isGoogleAppEngine() { public static boolean isGoogleAppEngine() {
return GAE_VERSION != null; return GAE_VERSION != null;
} }

18
fine-kryo/src/com/fr/third/org/objenesis/strategy/SerializingInstantiatorStrategy.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -60,24 +60,24 @@ public class SerializingInstantiatorStrategy extends BaseInstantiatorStrategy {
if(JVM_NAME.startsWith(HOTSPOT) || PlatformDescription.isThisJVM(OPENJDK)) { if(JVM_NAME.startsWith(HOTSPOT) || PlatformDescription.isThisJVM(OPENJDK)) {
// Java 7 GAE was under a security manager so we use a degraded system // Java 7 GAE was under a security manager so we use a degraded system
if(isGoogleAppEngine() && PlatformDescription.SPECIFICATION_VERSION.equals("1.7")) { if(isGoogleAppEngine() && PlatformDescription.SPECIFICATION_VERSION.equals("1.7")) {
return new ObjectInputStreamInstantiator<T>(type); return new ObjectInputStreamInstantiator(type);
} }
return new SunReflectionFactorySerializationInstantiator<T>(type); return new SunReflectionFactorySerializationInstantiator(type);
} }
else if(JVM_NAME.startsWith(DALVIK)) { else if(JVM_NAME.startsWith(DALVIK)) {
if(PlatformDescription.isAndroidOpenJDK()) { if(PlatformDescription.isAndroidOpenJDK()) {
return new ObjectStreamClassInstantiator<T>(type); return new ObjectStreamClassInstantiator(type);
} }
return new AndroidSerializationInstantiator<T>(type); return new AndroidSerializationInstantiator(type);
} }
else if(JVM_NAME.startsWith(GNU)) { else if(JVM_NAME.startsWith(GNU)) {
return new GCJSerializationInstantiator<T>(type); return new GCJSerializationInstantiator(type);
} }
else if(JVM_NAME.startsWith(PERC)) { else if(JVM_NAME.startsWith(PERC)) {
return new PercSerializationInstantiator<T>(type); return new PercSerializationInstantiator(type);
} }
return new SunReflectionFactorySerializationInstantiator<T>(type); return new SunReflectionFactorySerializationInstantiator(type);
} }
} }

12
fine-kryo/src/com/fr/third/org/objenesis/strategy/SingleInstantiatorStrategy.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,8 +15,8 @@
*/ */
package com.fr.third.org.objenesis.strategy; package com.fr.third.org.objenesis.strategy;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.ObjenesisException; import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -59,11 +59,7 @@ public class SingleInstantiatorStrategy implements InstantiatorStrategy {
public <T> ObjectInstantiator<T> newInstantiatorOf(Class<T> type) { public <T> ObjectInstantiator<T> newInstantiatorOf(Class<T> type) {
try { try {
return (ObjectInstantiator<T>) constructor.newInstance(type); return (ObjectInstantiator<T>) constructor.newInstance(type);
} catch (InstantiationException e) { } catch (Exception e) {
throw new ObjenesisException(e);
} catch (IllegalAccessException e) {
throw new ObjenesisException(e);
} catch (InvocationTargetException e) {
throw new ObjenesisException(e); throw new ObjenesisException(e);
} }
} }

29
fine-kryo/src/com/fr/third/org/objenesis/strategy/StdInstantiatorStrategy.java

@ -1,5 +1,5 @@
/** /*
* Copyright 2006-2017 the original author or authors. * Copyright 2006-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -53,49 +53,46 @@ public class StdInstantiatorStrategy extends BaseInstantiatorStrategy {
* @param type Class to instantiate * @param type Class to instantiate
* @return The ObjectInstantiator for the class * @return The ObjectInstantiator for the class
*/ */
@Override
public <T> ObjectInstantiator<T> newInstantiatorOf(Class<T> type) { public <T> ObjectInstantiator<T> newInstantiatorOf(Class<T> type) {
if(PlatformDescription.isThisJVM(HOTSPOT) || PlatformDescription.isThisJVM(OPENJDK)) { if(PlatformDescription.isThisJVM(HOTSPOT) || PlatformDescription.isThisJVM(OPENJDK)) {
// Java 7 GAE was under a security manager so we use a degraded system // Java 7 GAE was under a security manager so we use a degraded system
if(PlatformDescription.isGoogleAppEngine() && PlatformDescription.SPECIFICATION_VERSION.equals("1.7")) { if(PlatformDescription.isGoogleAppEngine() && PlatformDescription.SPECIFICATION_VERSION.equals("1.7")) {
if(Serializable.class.isAssignableFrom(type)) { if(Serializable.class.isAssignableFrom(type)) {
return new ObjectInputStreamInstantiator<T>(type); return new ObjectInputStreamInstantiator(type);
} }
return new AccessibleInstantiator<T>(type); return new AccessibleInstantiator(type);
} }
// The UnsafeFactoryInstantiator would also work. But according to benchmarks, it is 2.5 // The UnsafeFactoryInstantiator would also work. But according to benchmarks, it is 2.5
// times slower. So I prefer to use this one // times slower. So I prefer to use this one
return new SunReflectionFactoryInstantiator<T>(type); return new SunReflectionFactoryInstantiator(type);
} }
else if(PlatformDescription.isThisJVM(DALVIK)) { else if(PlatformDescription.isThisJVM(DALVIK)) {
if(PlatformDescription.isAndroidOpenJDK()) { if(PlatformDescription.isAndroidOpenJDK()) {
// Starting at Android N which is based on OpenJDK // Starting at Android N which is based on OpenJDK
return new UnsafeFactoryInstantiator<T>(type); return new UnsafeFactoryInstantiator(type);
} }
if(ANDROID_VERSION <= 10) { if(ANDROID_VERSION <= 10) {
// Android 2.3 Gingerbread and lower // Android 2.3 Gingerbread and lower
return new Android10Instantiator<T>(type); return new Android10Instantiator(type);
} }
if(ANDROID_VERSION <= 17) { if(ANDROID_VERSION <= 17) {
// Android 3.0 Honeycomb to 4.2 Jelly Bean // Android 3.0 Honeycomb to 4.2 Jelly Bean
return new Android17Instantiator<T>(type); return new Android17Instantiator(type);
} }
// Android 4.3 until Android N // Android 4.3 until Android N
return new Android18Instantiator<T>(type); return new Android18Instantiator(type);
}
else if(PlatformDescription.isThisJVM(JROCKIT)) {
// JRockit is compliant with HotSpot
return new SunReflectionFactoryInstantiator<T>(type);
} }
else if(PlatformDescription.isThisJVM(GNU)) { else if(PlatformDescription.isThisJVM(GNU)) {
return new GCJInstantiator<T>(type); return new GCJInstantiator(type);
} }
else if(PlatformDescription.isThisJVM(PERC)) { else if(PlatformDescription.isThisJVM(PERC)) {
return new PercInstantiator<T>(type); return new PercInstantiator(type);
} }
// Fallback instantiator, should work with most modern JVM // Fallback instantiator, should work with most modern JVM
return new UnsafeFactoryInstantiator<T>(type); return new UnsafeFactoryInstantiator(type);
} }
} }

Loading…
Cancel
Save