Browse Source

Merge pull request #309 in CORE/base-third from ~ZHOUPING/base-third:feature/10.0 to feature/10.0

* commit '2c13b67f92c5e101d2de7ba7c45c74661b09e5c3':
  KERNEL-1324 fine-kryo支持JDK11
research/11.0
zhouping 5 years ago
parent
commit
815363a3d3
  1. 2
      fine-kryo/src/com/fr/third/esotericsoftware/kryo/util/UnsafeUtil.java
  2. 116
      fine-kryo/src/com/fr/third/org/objenesis/ObjenesisBase.java
  3. 78
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/ClassUtils.java
  4. 147
      fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/DefineClassHelper.java
  5. 4
      fine-objenesis/src/com/fr/third/org/objenesis/Objenesis.java
  6. 102
      fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisBase.java
  7. 4
      fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisException.java
  8. 6
      fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisHelper.java
  9. 13
      fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisSerializer.java
  10. 15
      fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisStd.java
  11. 4
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/ObjectInstantiator.java
  12. 4
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/SerializationInstantiatorHelper.java
  13. 11
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/android/Android10Instantiator.java
  14. 22
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/android/Android17Instantiator.java
  15. 24
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/android/Android18Instantiator.java
  16. 25
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/android/AndroidSerializationInstantiator.java
  17. 4
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/annotations/Instantiator.java
  18. 4
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/annotations/Typology.java
  19. 7
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/AccessibleInstantiator.java
  20. 6
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ConstructorInstantiator.java
  21. 6
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/FailingInstantiator.java
  22. 13
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/NewInstanceInstantiator.java
  23. 4
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/NullInstantiator.java
  24. 14
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java
  25. 11
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java
  26. 71
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ProxyingInstantiator.java
  27. 15
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiator.java
  28. 17
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiatorBase.java
  29. 9
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/gcj/GCJSerializationInstantiator.java
  30. 15
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/perc/PercInstantiator.java
  31. 28
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/perc/PercSerializationInstantiator.java
  32. 97
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/MagicInstantiator.java
  33. 25
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryHelper.java
  34. 6
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java
  35. 6
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java
  36. 8
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java
  37. 74
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/util/ClassDefinitionUtils.java
  38. 149
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/util/DefineClassHelper.java
  39. 4
      fine-objenesis/src/com/fr/third/org/objenesis/instantiator/util/UnsafeUtils.java
  40. 4
      fine-objenesis/src/com/fr/third/org/objenesis/strategy/BaseInstantiatorStrategy.java
  41. 4
      fine-objenesis/src/com/fr/third/org/objenesis/strategy/InstantiatorStrategy.java
  42. 16
      fine-objenesis/src/com/fr/third/org/objenesis/strategy/PlatformDescription.java
  43. 18
      fine-objenesis/src/com/fr/third/org/objenesis/strategy/SerializingInstantiatorStrategy.java
  44. 12
      fine-objenesis/src/com/fr/third/org/objenesis/strategy/SingleInstantiatorStrategy.java
  45. 29
      fine-objenesis/src/com/fr/third/org/objenesis/strategy/StdInstantiatorStrategy.java
  46. 96
      fine-third-jdk11/src/com/fr/third/sun/misc/BASE64Decoder.java
  47. 62
      fine-third-jdk11/src/com/fr/third/sun/misc/BASE64Encoder.java
  48. 16
      fine-third-jdk11/src/com/fr/third/sun/misc/CEFormatException.java
  49. 15
      fine-third-jdk11/src/com/fr/third/sun/misc/CEStreamExhausted.java
  50. 107
      fine-third-jdk11/src/com/fr/third/sun/misc/CharacterDecoder.java
  51. 186
      fine-third-jdk11/src/com/fr/third/sun/misc/CharacterEncoder.java
  52. 84
      fine-third-jdk11/src/com/fr/third/sun/misc/Cleaner.java

2
fine-kryo/src/com/fr/third/esotericsoftware/kryo/util/UnsafeUtil.java

@ -27,7 +27,7 @@ import java.util.Comparator;
import java.util.List;
import com.fr.third.esotericsoftware.minlog.Log;
import sun.misc.Cleaner;
import com.fr.third.sun.misc.Cleaner;
import sun.misc.Unsafe;
import sun.nio.ch.DirectBuffer;

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

@ -1,116 +0,0 @@
/*
* 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;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.strategy.InstantiatorStrategy;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Base class to extend if you want to have a class providing your own default strategy. Can also be
* instantiated directly.
*
* @author Henri Tremblay
*/
public class ObjenesisBase implements Objenesis {
/**
* Strategy used by this Objenesi implementation to create classes
*/
protected final InstantiatorStrategy strategy;
/**
* Strategy cache. Key = Class, Value = InstantiatorStrategy
*/
protected Map<Class, ObjectInstantiator<?>> cache;
/**
* Constructor allowing to pick a strategy and using cache
*
* @param strategy Strategy to use
*/
public ObjenesisBase(InstantiatorStrategy strategy) {
this(strategy, true);
}
/**
* Flexible constructor allowing to pick the strategy and if caching should be used
*
* @param strategy Strategy to use
* @param useCache If {@link ObjectInstantiator}s should be cached
*/
public ObjenesisBase(InstantiatorStrategy strategy, boolean useCache) {
if (strategy == null) {
throw new IllegalArgumentException("A strategy can't be null");
}
this.strategy = strategy;
this.cache = useCache ? new ConcurrentHashMap<Class, ObjectInstantiator<?>>() : null;
}
@Override
public String toString() {
return getClass().getName() + " using " + strategy.getClass().getName()
+ (cache == null ? " without" : " with") + " caching";
}
/**
* Will create a new object without any constructor being called
*
* @param clazz Class to instantiate
* @return New instance of clazz
*/
public <T> T newInstance(Class<T> clazz) {
return getInstantiatorOf(clazz).newInstance();
}
/**
* Will pick the best instantiator for the provided class. If you need to create a lot of
* instances from the same class, it is way more efficient to create them from the same
* ObjectInstantiator than calling {@link #newInstance(Class)}.
*
* @param clazz Class to instantiate
* @return Instantiator dedicated to the class
*/
@SuppressWarnings("unchecked")
public <T> ObjectInstantiator<T> getInstantiatorOf(Class<T> clazz) {
if (clazz.isPrimitive()) {
throw new IllegalArgumentException("Primitive types can't be instantiated in Java");
}
if (cache == null) {
return strategy.newInstantiatorOf(clazz);
}
ObjectInstantiator<?> instantiator = cache.get(clazz);
if (instantiator == null) {
ObjectInstantiator<?> newInstantiator = strategy.newInstantiatorOf(clazz);
instantiator = putIfAbsent(clazz, newInstantiator);
if (instantiator == null) {
instantiator = newInstantiator;
}
}
return (ObjectInstantiator<T>) instantiator;
}
private ObjectInstantiator<?> putIfAbsent(Class key, ObjectInstantiator<?> newInstantiator) {
ObjectInstantiator<?> instantiator = cache.get(key);
if (instantiator == null) {
instantiator = cache.put(key, newInstantiator);
}
return instantiator;
}
}

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

@ -1,78 +0,0 @@
/*
* 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

@ -1,147 +0,0 @@
/*
* 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/Objenesis.java → fine-objenesis/src/com/fr/third/org/objenesis/Objenesis.java

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.

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

@ -0,0 +1,102 @@
/**
* Copyright 2006-2017 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;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.strategy.InstantiatorStrategy;
import java.util.concurrent.ConcurrentHashMap;
/**
* Base class to extend if you want to have a class providing your own default strategy. Can also be
* instantiated directly.
*
* @author Henri Tremblay
*/
public class ObjenesisBase implements Objenesis {
/** Strategy used by this Objenesi implementation to create classes */
protected final InstantiatorStrategy strategy;
/** Strategy cache. Key = Class, Value = InstantiatorStrategy */
protected ConcurrentHashMap<String, ObjectInstantiator<?>> cache;
/**
* Constructor allowing to pick a strategy and using cache
*
* @param strategy Strategy to use
*/
public ObjenesisBase(InstantiatorStrategy strategy) {
this(strategy, true);
}
/**
* Flexible constructor allowing to pick the strategy and if caching should be used
*
* @param strategy Strategy to use
* @param useCache If {@link ObjectInstantiator}s should be cached
*/
public ObjenesisBase(InstantiatorStrategy strategy, boolean useCache) {
if(strategy == null) {
throw new IllegalArgumentException("A strategy can't be null");
}
this.strategy = strategy;
this.cache = useCache ? new ConcurrentHashMap<String, ObjectInstantiator<?>>() : null;
}
@Override
public String toString() {
return getClass().getName() + " using " + strategy.getClass().getName()
+ (cache == null ? " without" : " with") + " caching";
}
/**
* Will create a new object without any constructor being called
*
* @param clazz Class to instantiate
* @return New instance of clazz
*/
public <T> T newInstance(Class<T> clazz) {
return getInstantiatorOf(clazz).newInstance();
}
/**
* Will pick the best instantiator for the provided class. If you need to create a lot of
* instances from the same class, it is way more efficient to create them from the same
* ObjectInstantiator than calling {@link #newInstance(Class)}.
*
* @param clazz Class to instantiate
* @return Instantiator dedicated to the class
*/
@SuppressWarnings("unchecked")
public <T> ObjectInstantiator<T> getInstantiatorOf(Class<T> clazz) {
if(clazz.isPrimitive()) {
throw new IllegalArgumentException("Primitive types can't be instantiated in Java");
}
if(cache == null) {
return strategy.newInstantiatorOf(clazz);
}
ObjectInstantiator<?> instantiator = cache.get(clazz.getName());
if(instantiator == null) {
ObjectInstantiator<?> newInstantiator = strategy.newInstantiatorOf(clazz);
instantiator = cache.putIfAbsent(clazz.getName(), newInstantiator);
if(instantiator == null) {
instantiator = newInstantiator;
}
}
return (ObjectInstantiator<T>) instantiator;
}
}

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -53,7 +53,7 @@ public final class ObjenesisHelper {
* @return New instance of clazz
*/
public static <T extends Serializable> T newSerializableInstance(Class<T> clazz) {
return OBJENESIS_SERIALIZER.newInstance(clazz);
return (T) OBJENESIS_SERIALIZER.newInstance(clazz);
}
/**

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -15,6 +15,7 @@
*/
package com.fr.third.org.objenesis;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.strategy.SerializingInstantiatorStrategy;
/**
@ -25,17 +26,17 @@ import com.fr.third.org.objenesis.strategy.SerializingInstantiatorStrategy;
public class ObjenesisSerializer extends ObjenesisBase {
/**
* Default constructor using the {@link com.fr.third.org.objenesis.strategy.SerializingInstantiatorStrategy}
* Default constructor using the {@link SerializingInstantiatorStrategy}
*/
public ObjenesisSerializer() {
super(new SerializingInstantiatorStrategy());
}
/**
* Instance using the {@link com.fr.third.org.objenesis.strategy.SerializingInstantiatorStrategy} with or without caching
* {@link com.fr.third.org.objenesis.instantiator.ObjectInstantiator}s
* Instance using the {@link SerializingInstantiatorStrategy} with or without caching
* {@link ObjectInstantiator}s
*
* @param useCache If {@link com.fr.third.org.objenesis.instantiator.ObjectInstantiator}s should be cached
* @param useCache If {@link ObjectInstantiator}s should be cached
*/
public ObjenesisSerializer(boolean useCache) {
super(new SerializingInstantiatorStrategy(), useCache);

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -15,27 +15,28 @@
*/
package com.fr.third.org.objenesis;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.strategy.StdInstantiatorStrategy;
/**
* Objenesis implementation using the {@link com.fr.third.org.objenesis.strategy.StdInstantiatorStrategy}.
* Objenesis implementation using the {@link StdInstantiatorStrategy}.
*
* @author Henri Tremblay
*/
public class ObjenesisStd extends ObjenesisBase {
/**
* Default constructor using the {@link com.fr.third.org.objenesis.strategy.StdInstantiatorStrategy}
* Default constructor using the {@link StdInstantiatorStrategy}
*/
public ObjenesisStd() {
super(new StdInstantiatorStrategy());
}
/**
* Instance using the {@link com.fr.third.org.objenesis.strategy.StdInstantiatorStrategy} with or without
* caching {@link com.fr.third.org.objenesis.instantiator.ObjectInstantiator}s
* Instance using the {@link StdInstantiatorStrategy} with or without
* caching {@link ObjectInstantiator}s
*
* @param useCache If {@link com.fr.third.org.objenesis.instantiator.ObjectInstantiator}s should be cached
* @param useCache If {@link ObjectInstantiator}s should be cached
*/
public ObjenesisStd(boolean useCache) {
super(new StdInstantiatorStrategy(), useCache);

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -18,10 +18,10 @@ package com.fr.third.org.objenesis.instantiator.android;
import java.io.ObjectInputStream;
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.annotations.Instantiator;
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
@ -56,7 +56,10 @@ public class Android10Instantiator<T> implements ObjectInstantiator<T> {
newStaticMethod.setAccessible(true);
return newStaticMethod;
}
catch(Exception e) {
catch(RuntimeException e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e);
}
}

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -19,10 +19,10 @@ import java.io.ObjectStreamClass;
import java.lang.reflect.InvocationTargetException;
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.annotations.Instantiator;
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
@ -58,7 +58,10 @@ public class Android17Instantiator<T> implements ObjectInstantiator<T> {
newInstanceMethod.setAccessible(true);
return newInstanceMethod;
}
catch(Exception e) {
catch(RuntimeException e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e);
}
}
@ -71,7 +74,16 @@ public class Android17Instantiator<T> implements ObjectInstantiator<T> {
return (Integer) newInstanceMethod.invoke(null, Object.class);
}
catch(Exception e) {
catch(RuntimeException 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);
}
}

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

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

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -19,10 +19,10 @@ import java.io.ObjectStreamClass;
import java.lang.reflect.InvocationTargetException;
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.annotations.Instantiator;
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
@ -40,7 +40,7 @@ public class AndroidSerializationInstantiator<T> implements ObjectInstantiator<T
public AndroidSerializationInstantiator(Class<T> type) {
this.type = type;
newInstanceMethod = getNewInstanceMethod();
Method m;
Method m = null;
try {
m = ObjectStreamClass.class.getMethod("lookupAny", Class.class);
} catch (NoSuchMethodException e) {
@ -48,7 +48,9 @@ public class AndroidSerializationInstantiator<T> implements ObjectInstantiator<T
}
try {
objectStreamClass = (ObjectStreamClass) m.invoke(null, type);
} catch (Exception e) {
} catch (IllegalAccessException e) {
throw new ObjenesisException(e);
} catch (InvocationTargetException e) {
throw new ObjenesisException(e);
}
}
@ -57,7 +59,13 @@ public class AndroidSerializationInstantiator<T> implements ObjectInstantiator<T
try {
return type.cast(newInstanceMethod.invoke(objectStreamClass, type));
}
catch(Exception e) {
catch(IllegalAccessException e) {
throw new ObjenesisException(e);
}
catch(IllegalArgumentException e) {
throw new ObjenesisException(e);
}
catch(InvocationTargetException e) {
throw new ObjenesisException(e);
}
}
@ -69,7 +77,10 @@ public class AndroidSerializationInstantiator<T> implements ObjectInstantiator<T
newInstanceMethod.setAccessible(true);
return newInstanceMethod;
}
catch(Exception e) {
catch(RuntimeException e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e);
}
}

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -15,6 +15,7 @@
*/
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.Typology;
@ -24,7 +25,7 @@ import com.fr.third.org.objenesis.instantiator.annotations.Typology;
* non-public constructors (if the security manager allows it).
*
* @author Joe Walnes
* @see com.fr.third.org.objenesis.instantiator.ObjectInstantiator
* @see ObjectInstantiator
*/
@Instantiator(Typology.NOT_COMPLIANT)
public class AccessibleInstantiator<T> extends ConstructorInstantiator<T> {

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -17,10 +17,10 @@ package com.fr.third.org.objenesis.instantiator.basic;
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.annotations.Instantiator;
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().

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -15,10 +15,10 @@
*/
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.annotations.Instantiator;
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

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -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.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology;
import com.fr.third.org.objenesis.instantiator.util.ClassUtils;
import com.fr.third.org.objenesis.ObjenesisException;
/**
* The simplest instantiator - simply calls Class.newInstance(). This can deal with default public
@ -37,7 +37,12 @@ public class NewInstanceInstantiator<T> implements ObjectInstantiator<T> {
}
public T newInstance() {
return ClassUtils.newInstance(type);
try {
return type.newInstance();
}
catch(Exception e) {
throw new ObjenesisException(e);
}
}
}

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -25,10 +25,10 @@ import java.io.ObjectStreamClass;
import java.io.ObjectStreamConstants;
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.annotations.Instantiator;
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
@ -38,7 +38,7 @@ import com.fr.third.org.objenesis.instantiator.annotations.Typology;
* completely different class.
*
* @author Leonardo Mesquita
* @see com.fr.third.org.objenesis.instantiator.ObjectInstantiator
* @see ObjectInstantiator
*/
@Instantiator(Typology.SERIALIZATION)
public class ObjectInputStreamInstantiator<T> implements ObjectInstantiator<T> {
@ -120,7 +120,7 @@ public class ObjectInputStreamInstantiator<T> implements ObjectInstantiator<T> {
}
@Override
public int read() {
public int read() throws IOException {
int result = data[pointer++];
if(pointer >= data.length) {
advanceBuffer();
@ -130,12 +130,12 @@ public class ObjectInputStreamInstantiator<T> implements ObjectInstantiator<T> {
}
@Override
public int available() {
public int available() throws IOException {
return Integer.MAX_VALUE;
}
@Override
public int read(byte[] b, int off, int len) {
public int read(byte[] b, int off, int len) throws IOException {
int left = len;
int remaining = data.length - pointer;

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -18,10 +18,10 @@ package com.fr.third.org.objenesis.instantiator.basic;
import java.io.ObjectStreamClass;
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.annotations.Instantiator;
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
@ -44,7 +44,10 @@ public class ObjectStreamClassInstantiator<T> implements ObjectInstantiator<T> {
newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod("newInstance");
newInstanceMethod.setAccessible(true);
}
catch(Exception e) {
catch(RuntimeException e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e);
}
}

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

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

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -17,6 +17,7 @@ package com.fr.third.org.objenesis.instantiator.gcj;
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.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology;
@ -26,7 +27,7 @@ import com.fr.third.org.objenesis.instantiator.annotations.Typology;
* work on GCJ JVMs. This instantiator will not call any constructors.
*
* @author Leonardo Mesquita
* @see com.fr.third.org.objenesis.instantiator.ObjectInstantiator
* @see ObjectInstantiator
*/
@Instantiator(Typology.STANDARD)
public class GCJInstantiator<T> extends GCJInstantiatorBase<T> {
@ -39,7 +40,13 @@ public class GCJInstantiator<T> extends GCJInstantiatorBase<T> {
try {
return type.cast(newObjectMethod.invoke(dummyStream, type, Object.class));
}
catch(Exception e) {
catch(RuntimeException e) {
throw new ObjenesisException(e);
}
catch(IllegalAccessException e) {
throw new ObjenesisException(e);
}
catch(InvocationTargetException e) {
throw new ObjenesisException(e);
}
}

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -19,8 +19,8 @@ import java.io.IOException;
import java.io.ObjectInputStream;
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.ObjenesisException;
/**
* Base class for GCJ-based instantiators. It initializes reflection access to method
@ -41,11 +41,18 @@ public abstract class GCJInstantiatorBase<T> implements ObjectInstantiator<T> {
private static void initialize() {
if(newObjectMethod == null) {
try {
newObjectMethod = ObjectInputStream.class.getDeclaredMethod("newObject", Class.class, Class.class);
newObjectMethod = ObjectInputStream.class.getDeclaredMethod("newObject", new Class[] {
Class.class, Class.class});
newObjectMethod.setAccessible(true);
dummyStream = new DummyStream();
}
catch(Exception e) {
catch(RuntimeException e) {
throw new ObjenesisException(e);
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e);
}
catch(IOException e) {
throw new ObjenesisException(e);
}
}

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -15,6 +15,7 @@
*/
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.instantiator.SerializationInstantiatorHelper;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
@ -26,11 +27,11 @@ import com.fr.third.org.objenesis.instantiator.annotations.Typology;
* calling the first non-serializable superclass' no-arg constructor.
*
* @author Leonardo Mesquita
* @see com.fr.third.org.objenesis.instantiator.ObjectInstantiator
* @see ObjectInstantiator
*/
@Instantiator(Typology.SERIALIZATION)
public class GCJSerializationInstantiator<T> extends GCJInstantiatorBase<T> {
private final Class<? super T> superType;
private Class<? super T> superType;
public GCJSerializationInstantiator(Class<T> type) {
super(type);

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -18,8 +18,8 @@ package com.fr.third.org.objenesis.instantiator.perc;
import java.io.ObjectInputStream;
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.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
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.
*
* @author Henri Tremblay
* @see com.fr.third.org.objenesis.instantiator.ObjectInstantiator
* @see ObjectInstantiator
*/
@Instantiator(Typology.STANDARD)
public class PercInstantiator<T> implements ObjectInstantiator<T> {
@ -47,10 +47,13 @@ public class PercInstantiator<T> implements ObjectInstantiator<T> {
Boolean.TYPE);
newInstanceMethod.setAccessible(true);
}
catch(Exception e) {
catch(RuntimeException e) {
throw new ObjenesisException(e);
}
}
catch(NoSuchMethodException e) {
throw new ObjenesisException(e);
}
}
@SuppressWarnings("unchecked")
public T newInstance() {

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -20,8 +20,8 @@ import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
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.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
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>
*
* @author Henri Tremblay
* @see com.fr.third.org.objenesis.instantiator.ObjectInstantiator
* @see ObjectInstantiator
*/
@Instantiator(Typology.SERIALIZATION)
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");
newInstanceMethod = ObjectInputStream.class.getDeclaredMethod("noArgConstruct",
Class.class, Object.class, percMethodClass);
new Class[] {Class.class, Object.class, percMethodClass});
newInstanceMethod.setAccessible(true);
// Create invoke params
@ -64,13 +64,22 @@ public class PercSerializationInstantiator<T> implements ObjectInstantiator<T> {
Method getPercClassMethod = percClassClass.getDeclaredMethod("getPercClass", Class.class);
Object someObject = getPercClassMethod.invoke(null, unserializableType);
Method findMethodMethod = someObject.getClass().getDeclaredMethod("findMethod",
String.class);
new Class[] {String.class});
Object percMethod = findMethodMethod.invoke(someObject, "<init>()V");
typeArgs = new Object[] {unserializableType, type, percMethod};
}
catch(Exception e) {
catch(ClassNotFoundException 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);
}
}
@ -80,7 +89,10 @@ public class PercSerializationInstantiator<T> implements ObjectInstantiator<T> {
try {
return (T) newInstanceMethod.invoke(null, typeArgs);
}
catch(Exception e) {
catch(IllegalAccessException e) {
throw new ObjenesisException(e);
}
catch(InvocationTargetException e) {
throw new ObjenesisException(e);
}
}

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

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

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -18,8 +18,8 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
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.ObjenesisException;
/**
@ -44,7 +44,13 @@ class SunReflectionFactoryHelper {
return (Constructor<T>) newConstructorForSerializationMethod.invoke(
reflectionFactory, type, constructor);
}
catch(Exception e) {
catch(IllegalArgumentException e) {
throw new ObjenesisException(e);
}
catch(IllegalAccessException e) {
throw new ObjenesisException(e);
}
catch(InvocationTargetException e) {
throw new ObjenesisException(e);
}
}
@ -64,7 +70,16 @@ class SunReflectionFactoryHelper {
"getReflectionFactory");
return method.invoke(null);
}
catch(Exception e) {
catch(NoSuchMethodException 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);
}
}

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -17,8 +17,8 @@ package com.fr.third.org.objenesis.instantiator.sun;
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.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.annotations.Instantiator;
import com.fr.third.org.objenesis.instantiator.annotations.Typology;

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -18,8 +18,8 @@ package com.fr.third.org.objenesis.instantiator.sun;
import java.io.NotSerializableException;
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.ObjenesisException;
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.Typology;

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -15,12 +15,12 @@
*/
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 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.Typology;
import com.fr.third.org.objenesis.instantiator.util.UnsafeUtils;
/**
* Instantiates an object, WITHOUT calling it's constructor, using

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -67,11 +67,15 @@ public final class ClassDefinitionUtils {
private ClassDefinitionUtils() { }
// private static Method DEFINE_CLASS;
private static final ProtectionDomain PROTECTION_DOMAIN;
static {
PROTECTION_DOMAIN = AccessController.doPrivileged((PrivilegedAction<ProtectionDomain>) ClassDefinitionUtils.class.getProtectionDomain());
PROTECTION_DOMAIN = AccessController.doPrivileged(new PrivilegedAction<ProtectionDomain>() {
public ProtectionDomain run() {
return ClassDefinitionUtils.class.getProtectionDomain();
}
});
}
/**
@ -79,9 +83,8 @@ public final class ClassDefinitionUtils {
* <code>ReflectUtils.defineClass</code>
*
* @param <T> type of the class returned
* @param className class name in the format <code>com.fr.third.org.objenesis.MyClass</code>
* @param className class name in the format <code>org.objenesis.MyClass</code>
* @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
* @return the newly loaded class
* @throws Exception whenever something goes wrong
@ -89,7 +92,7 @@ public final class ClassDefinitionUtils {
@SuppressWarnings("unchecked")
public static <T> Class<T> defineClass(String className, byte[] b, Class<?> neighbor, ClassLoader loader)
throws Exception {
Class<T> c = (Class<T>) DefineClassHelper.defineClass(className, b, 0, b.length, neighbor, loader, PROTECTION_DOMAIN);
Class<T> c = (Class<T>) DefineClassHelper.defineClass(className, b, 0, b.length, neighbor, loader, PROTECTION_DOMAIN);
// Force static initializers to run.
Class.forName(className, true, loader);
return c;
@ -105,17 +108,18 @@ public final class ClassDefinitionUtils {
*/
public static byte[] readClass(String className) throws IOException {
// convert to a resource
className = ClassUtils.classNameToResource(className);
className = classNameToResource(className);
byte[] b = new byte[2500]; // I'm assuming that I'm reading class that are not too big
int length=0;
int length;
InputStream in = ClassDefinitionUtils.class.getClassLoader().getResourceAsStream(className);
try {
InputStream in = ClassDefinitionUtils.class.getClassLoader().getResourceAsStream(className);
length = in.read(b);
} catch (Exception e) {
}
finally {
in.close();
}
if(length >= 2500) {
@ -135,12 +139,52 @@ public final class ClassDefinitionUtils {
* @throws IOException if we fail to write the class
*/
public static void writeClass(String fileName, byte[] bytes) throws IOException {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
try {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
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;
}
}
}

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

@ -0,0 +1,149 @@
/*
* Copyright 2006-2019 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;
import com.fr.third.org.objenesis.strategy.PlatformDescription;
import sun.misc.Unsafe;
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(NoSuchMethodException | IllegalAccessException 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 (NoSuchMethodException | IllegalAccessException e) {
throw new ObjenesisException(e);
}
}
private MethodHandle addReads() {
try {
return lookup.findVirtual(module, "addReads", MethodType.methodType(module, module));
} catch (NoSuchMethodException | IllegalAccessException 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 (NoSuchMethodException | IllegalAccessException e) {
throw new ObjenesisException(e);
}
}
private MethodHandle defineClass() {
try {
return lookup.findVirtual(MethodHandles.Lookup.class, "defineClass", MethodType.methodType(Class.class, byte[].class));
} catch (NoSuchMethodException | IllegalAccessException 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 → fine-objenesis/src/com/fr/third/org/objenesis/instantiator/util/UnsafeUtils.java

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -15,10 +15,10 @@
*/
package com.fr.third.org.objenesis.strategy;
import java.lang.reflect.Field;
import com.fr.third.org.objenesis.ObjenesisException;
import java.lang.reflect.Field;
/**
* List of constants describing the currently used platform.
*
@ -26,6 +26,9 @@ import com.fr.third.org.objenesis.ObjenesisException;
*/
public final class PlatformDescription {
/** JVM_NAME prefix for JRockit */
public static final String JROCKIT = "BEA";
/** JVM_NAME prefix for GCJ */
public static final String GNU = "GNU libgcj";
@ -90,8 +93,9 @@ public final class PlatformDescription {
+ "JVM version=" + VM_VERSION + ", "
+ "JVM info=" + VM_INFO;
// Add the API level if it's an Android platform
if(ANDROID_VERSION != 0) {
// Add the API level is it's an Android platform
int androidVersion = ANDROID_VERSION;
if(androidVersion != 0) {
desc += ", API level=" + ANDROID_VERSION;
}
desc += ")";

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

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

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

@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
/**
* Copyright 2006-2017 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.
@ -15,8 +15,8 @@
*/
package com.fr.third.org.objenesis.strategy;
import com.fr.third.org.objenesis.ObjenesisException;
import com.fr.third.org.objenesis.instantiator.ObjectInstantiator;
import com.fr.third.org.objenesis.ObjenesisException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@ -59,7 +59,11 @@ public class SingleInstantiatorStrategy implements InstantiatorStrategy {
public <T> ObjectInstantiator<T> newInstantiatorOf(Class<T> type) {
try {
return (ObjectInstantiator<T>) constructor.newInstance(type);
} catch (Exception e) {
} catch (InstantiationException e) {
throw new ObjenesisException(e);
} catch (IllegalAccessException e) {
throw new ObjenesisException(e);
} catch (InvocationTargetException e) {
throw new ObjenesisException(e);
}
}

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

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

96
fine-third-jdk11/src/com/fr/third/sun/misc/BASE64Decoder.java

@ -0,0 +1,96 @@
package com.fr.third.sun.misc;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PushbackInputStream;
/**
* @author zhouping
* @version 10.0
* Created by zhouping on 2019/10/28
*/
public class BASE64Decoder extends CharacterDecoder {
private static final char[] pem_array = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
private static final byte[] pem_convert_array = new byte[256];
byte[] decode_buffer = new byte[4];
public BASE64Decoder() {
}
protected int bytesPerAtom() {
return 4;
}
protected int bytesPerLine() {
return 72;
}
protected void decodeAtom(PushbackInputStream var1, OutputStream var2, int var3) throws IOException {
byte var5 = -1;
byte var6 = -1;
byte var7 = -1;
byte var8 = -1;
if (var3 < 2) {
throw new CEFormatException("BASE64Decoder: Not enough bytes for an atom.");
} else {
int var4;
do {
var4 = var1.read();
if (var4 == -1) {
throw new CEStreamExhausted();
}
} while(var4 == 10 || var4 == 13);
this.decode_buffer[0] = (byte)var4;
var4 = this.readFully(var1, this.decode_buffer, 1, var3 - 1);
if (var4 == -1) {
throw new CEStreamExhausted();
} else {
if (var3 > 3 && this.decode_buffer[3] == 61) {
var3 = 3;
}
if (var3 > 2 && this.decode_buffer[2] == 61) {
var3 = 2;
}
switch(var3) {
case 4:
var8 = pem_convert_array[this.decode_buffer[3] & 255];
case 3:
var7 = pem_convert_array[this.decode_buffer[2] & 255];
case 2:
var6 = pem_convert_array[this.decode_buffer[1] & 255];
var5 = pem_convert_array[this.decode_buffer[0] & 255];
default:
switch(var3) {
case 2:
var2.write((byte)(var5 << 2 & 252 | var6 >>> 4 & 3));
break;
case 3:
var2.write((byte)(var5 << 2 & 252 | var6 >>> 4 & 3));
var2.write((byte)(var6 << 4 & 240 | var7 >>> 2 & 15));
break;
case 4:
var2.write((byte)(var5 << 2 & 252 | var6 >>> 4 & 3));
var2.write((byte)(var6 << 4 & 240 | var7 >>> 2 & 15));
var2.write((byte)(var7 << 6 & 192 | var8 & 63));
}
}
}
}
}
static {
int var0;
for(var0 = 0; var0 < 255; ++var0) {
pem_convert_array[var0] = -1;
}
for(var0 = 0; var0 < pem_array.length; ++var0) {
pem_convert_array[pem_array[var0]] = (byte)var0;
}
}
}

62
fine-third-jdk11/src/com/fr/third/sun/misc/BASE64Encoder.java

@ -0,0 +1,62 @@
package com.fr.third.sun.misc;
import java.io.IOException;
import java.io.OutputStream;
/**
* @author zhouping
* @version 10.0
* Created by zhouping on 2019/10/28
*/
public class BASE64Encoder extends CharacterEncoder {
private static final char[] pem_array = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
public BASE64Encoder() {
}
protected int bytesPerAtom() {
return 3;
}
protected int bytesPerLine() {
return 57;
}
protected void encodeAtom(OutputStream var1, byte[] var2, int var3, int var4) throws IOException {
byte var5;
if (var4 == 1) {
var5 = var2[var3];
byte var6 = 0;
boolean var7 = false;
var1.write(pem_array[var5 >>> 2 & 63]);
var1.write(pem_array[(var5 << 4 & 48) + (var6 >>> 4 & 15)]);
var1.write(61);
var1.write(61);
} else {
byte var8;
if (var4 == 2) {
var5 = var2[var3];
var8 = var2[var3 + 1];
byte var9 = 0;
var1.write(pem_array[var5 >>> 2 & 63]);
var1.write(pem_array[(var5 << 4 & 48) + (var8 >>> 4 & 15)]);
var1.write(pem_array[(var8 << 2 & 60) + (var9 >>> 6 & 3)]);
var1.write(61);
} else {
var5 = var2[var3];
var8 = var2[var3 + 1];
byte var10 = var2[var3 + 2];
var1.write(pem_array[var5 >>> 2 & 63]);
var1.write(pem_array[(var5 << 4 & 48) + (var8 >>> 4 & 15)]);
var1.write(pem_array[(var8 << 2 & 60) + (var10 >>> 6 & 3)]);
var1.write(pem_array[var10 & 63]);
}
}
}
}

16
fine-third-jdk11/src/com/fr/third/sun/misc/CEFormatException.java

@ -0,0 +1,16 @@
package com.fr.third.sun.misc;
import java.io.IOException;
/**
* @author zhouping
* @version 10.0
* Created by zhouping on 2019/10/28
*/
public class CEFormatException extends IOException {
public CEFormatException(String var1) {
super(var1);
}
}

15
fine-third-jdk11/src/com/fr/third/sun/misc/CEStreamExhausted.java

@ -0,0 +1,15 @@
package com.fr.third.sun.misc;
import java.io.IOException;
/**
* @author zhouping
* @version 10.0
* Created by zhouping on 2019/10/28
*/
public class CEStreamExhausted extends IOException {
public CEStreamExhausted() {
}
}

107
fine-third-jdk11/src/com/fr/third/sun/misc/CharacterDecoder.java

@ -0,0 +1,107 @@
package com.fr.third.sun.misc;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.nio.ByteBuffer;
/**
* @author zhouping
* @version 10.0
* Created by zhouping on 2019/10/28
*/
public abstract class CharacterDecoder {
public CharacterDecoder() {
}
protected abstract int bytesPerAtom();
protected abstract int bytesPerLine();
protected void decodeBufferPrefix(PushbackInputStream var1, OutputStream var2) throws IOException {
}
protected void decodeBufferSuffix(PushbackInputStream var1, OutputStream var2) throws IOException {
}
protected int decodeLinePrefix(PushbackInputStream var1, OutputStream var2) throws IOException {
return this.bytesPerLine();
}
protected void decodeLineSuffix(PushbackInputStream var1, OutputStream var2) throws IOException {
}
protected void decodeAtom(PushbackInputStream var1, OutputStream var2, int var3) throws IOException {
throw new CEStreamExhausted();
}
protected int readFully(InputStream var1, byte[] var2, int var3, int var4) throws IOException {
for(int var5 = 0; var5 < var4; ++var5) {
int var6 = var1.read();
if (var6 == -1) {
return var5 == 0 ? -1 : var5;
}
var2[var5 + var3] = (byte)var6;
}
return var4;
}
public void decodeBuffer(InputStream var1, OutputStream var2) throws IOException {
int var4 = 0;
PushbackInputStream var5 = new PushbackInputStream(var1);
this.decodeBufferPrefix(var5, var2);
while(true) {
try {
int var6 = this.decodeLinePrefix(var5, var2);
int var3;
for(var3 = 0; var3 + this.bytesPerAtom() < var6; var3 += this.bytesPerAtom()) {
this.decodeAtom(var5, var2, this.bytesPerAtom());
var4 += this.bytesPerAtom();
}
if (var3 + this.bytesPerAtom() == var6) {
this.decodeAtom(var5, var2, this.bytesPerAtom());
var4 += this.bytesPerAtom();
} else {
this.decodeAtom(var5, var2, var6 - var3);
var4 += var6 - var3;
}
this.decodeLineSuffix(var5, var2);
} catch (CEStreamExhausted var8) {
this.decodeBufferSuffix(var5, var2);
return;
}
}
}
public byte[] decodeBuffer(String var1) throws IOException {
byte[] var2 = new byte[var1.length()];
var1.getBytes(0, var1.length(), var2, 0);
ByteArrayInputStream var3 = new ByteArrayInputStream(var2);
ByteArrayOutputStream var4 = new ByteArrayOutputStream();
this.decodeBuffer(var3, var4);
return var4.toByteArray();
}
public byte[] decodeBuffer(InputStream var1) throws IOException {
ByteArrayOutputStream var2 = new ByteArrayOutputStream();
this.decodeBuffer(var1, var2);
return var2.toByteArray();
}
public ByteBuffer decodeBufferToByteBuffer(String var1) throws IOException {
return ByteBuffer.wrap(this.decodeBuffer(var1));
}
public ByteBuffer decodeBufferToByteBuffer(InputStream var1) throws IOException {
return ByteBuffer.wrap(this.decodeBuffer(var1));
}
}

186
fine-third-jdk11/src/com/fr/third/sun/misc/CharacterEncoder.java

@ -0,0 +1,186 @@
package com.fr.third.sun.misc;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.ByteBuffer;
/**
* @author zhouping
* @version 10.0
* Created by zhouping on 2019/10/28
*/
public abstract class CharacterEncoder {
protected PrintStream pStream;
public CharacterEncoder() {
}
protected abstract int bytesPerAtom();
protected abstract int bytesPerLine();
protected void encodeBufferPrefix(OutputStream var1) throws IOException {
this.pStream = new PrintStream(var1);
}
protected void encodeBufferSuffix(OutputStream var1) throws IOException {
}
protected void encodeLinePrefix(OutputStream var1, int var2) throws IOException {
}
protected void encodeLineSuffix(OutputStream var1) throws IOException {
this.pStream.println();
}
protected abstract void encodeAtom(OutputStream var1, byte[] var2, int var3, int var4) throws IOException;
protected int readFully(InputStream var1, byte[] var2) throws IOException {
for (int var3 = 0; var3 < var2.length; ++var3) {
int var4 = var1.read();
if (var4 == -1) {
return var3;
}
var2[var3] = (byte) var4;
}
return var2.length;
}
public void encode(InputStream var1, OutputStream var2) throws IOException {
byte[] var5 = new byte[this.bytesPerLine()];
this.encodeBufferPrefix(var2);
while (true) {
int var4 = this.readFully(var1, var5);
if (var4 == 0) {
break;
}
this.encodeLinePrefix(var2, var4);
for (int var3 = 0; var3 < var4; var3 += this.bytesPerAtom()) {
if (var3 + this.bytesPerAtom() <= var4) {
this.encodeAtom(var2, var5, var3, this.bytesPerAtom());
} else {
this.encodeAtom(var2, var5, var3, var4 - var3);
}
}
if (var4 < this.bytesPerLine()) {
break;
}
this.encodeLineSuffix(var2);
}
this.encodeBufferSuffix(var2);
}
public void encode(byte[] var1, OutputStream var2) throws IOException {
ByteArrayInputStream var3 = new ByteArrayInputStream(var1);
this.encode((InputStream) var3, var2);
}
public String encode(byte[] var1) {
ByteArrayOutputStream var2 = new ByteArrayOutputStream();
ByteArrayInputStream var3 = new ByteArrayInputStream(var1);
String var4 = null;
try {
this.encode((InputStream) var3, var2);
var4 = var2.toString("8859_1");
return var4;
} catch (Exception var6) {
throw new Error("CharacterEncoder.encode internal error");
}
}
private byte[] getBytes(ByteBuffer var1) {
byte[] var2 = null;
if (var1.hasArray()) {
byte[] var3 = var1.array();
if (var3.length == var1.capacity() && var3.length == var1.remaining()) {
var2 = var3;
var1.position(var1.limit());
}
}
if (var2 == null) {
var2 = new byte[var1.remaining()];
var1.get(var2);
}
return var2;
}
public void encode(ByteBuffer var1, OutputStream var2) throws IOException {
byte[] var3 = this.getBytes(var1);
this.encode(var3, var2);
}
public String encode(ByteBuffer var1) {
byte[] var2 = this.getBytes(var1);
return this.encode(var2);
}
public void encodeBuffer(InputStream var1, OutputStream var2) throws IOException {
byte[] var5 = new byte[this.bytesPerLine()];
this.encodeBufferPrefix(var2);
int var4;
do {
var4 = this.readFully(var1, var5);
if (var4 == 0) {
break;
}
this.encodeLinePrefix(var2, var4);
for (int var3 = 0; var3 < var4; var3 += this.bytesPerAtom()) {
if (var3 + this.bytesPerAtom() <= var4) {
this.encodeAtom(var2, var5, var3, this.bytesPerAtom());
} else {
this.encodeAtom(var2, var5, var3, var4 - var3);
}
}
this.encodeLineSuffix(var2);
} while (var4 >= this.bytesPerLine());
this.encodeBufferSuffix(var2);
}
public void encodeBuffer(byte[] var1, OutputStream var2) throws IOException {
ByteArrayInputStream var3 = new ByteArrayInputStream(var1);
this.encodeBuffer((InputStream) var3, var2);
}
public String encodeBuffer(byte[] var1) {
ByteArrayOutputStream var2 = new ByteArrayOutputStream();
ByteArrayInputStream var3 = new ByteArrayInputStream(var1);
try {
this.encodeBuffer((InputStream) var3, var2);
} catch (Exception var5) {
throw new Error("CharacterEncoder.encodeBuffer internal error");
}
return var2.toString();
}
public void encodeBuffer(ByteBuffer var1, OutputStream var2) throws IOException {
byte[] var3 = this.getBytes(var1);
this.encodeBuffer(var3, var2);
}
public String encodeBuffer(ByteBuffer var1) {
byte[] var2 = this.getBytes(var1);
return this.encodeBuffer(var2);
}
}

84
fine-third-jdk11/src/com/fr/third/sun/misc/Cleaner.java

@ -0,0 +1,84 @@
package com.fr.third.sun.misc;
import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* @author zhouping
* @version 10.0
* Created by zhouping on 2019/10/29
*/
public class Cleaner extends PhantomReference<Object> {
private static final ReferenceQueue<Object> dummyQueue = new ReferenceQueue();
private static Cleaner first = null;
private Cleaner next = null;
private Cleaner prev = null;
private final Runnable thunk;
private static synchronized Cleaner add(Cleaner var0) {
if (first != null) {
var0.next = first;
first.prev = var0;
}
first = var0;
return var0;
}
private static synchronized boolean remove(Cleaner var0) {
if (var0.next == var0) {
return false;
} else {
if (first == var0) {
if (var0.next != null) {
first = var0.next;
} else {
first = var0.prev;
}
}
if (var0.next != null) {
var0.next.prev = var0.prev;
}
if (var0.prev != null) {
var0.prev.next = var0.next;
}
var0.next = var0;
var0.prev = var0;
return true;
}
}
private Cleaner(Object var1, Runnable var2) {
super(var1, dummyQueue);
this.thunk = var2;
}
public static Cleaner create(Object var0, Runnable var1) {
return var1 == null ? null : add(new Cleaner(var0, var1));
}
public void clean() {
if (remove(this)) {
try {
this.thunk.run();
} catch (final Throwable var2) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
if (System.err != null) {
(new Error("Cleaner terminated abnormally", var2)).printStackTrace();
}
System.exit(1);
return null;
}
});
}
}
}
}
Loading…
Cancel
Save