diff --git a/build.third_step1.gradle b/build.third_step1.gradle index 2e561dc79..d035fd18d 100644 --- a/build.third_step1.gradle +++ b/build.third_step1.gradle @@ -32,6 +32,8 @@ sourceSets{ main{ java{ srcDirs=[ + "${srcDir}/fine-third-jdk11/src", + "${srcDir}/fine-objenesis/src", "${srcDir}/fine-jetbrains/src", "${srcDir}/fine-poi/src", "${srcDir}/fine-quartz/src", @@ -86,6 +88,8 @@ def dataContent ={def dir -> task copyFiles(type:Copy,dependsOn:'compileJava'){ copy{ println "------------------------------------------------copyfiles" + with dataContent.call("${srcDir}/fine-third-jdk11/src") + with dataContent.call("${srcDir}/fine-objenesis/src") with dataContent.call("${srcDir}/fine-jetbrains/src") with dataContent.call("${srcDir}/fine-poi/src") with dataContent.call("${srcDir}/fine-quartz/src") diff --git a/fine-spring/src/com/fr/third/springframework/aop/framework/ObjenesisCglibAopProxy.java b/fine-spring/src/com/fr/third/springframework/aop/framework/ObjenesisCglibAopProxy.java index c26d3d1e5..3f8c40cde 100644 --- a/fine-spring/src/com/fr/third/springframework/aop/framework/ObjenesisCglibAopProxy.java +++ b/fine-spring/src/com/fr/third/springframework/aop/framework/ObjenesisCglibAopProxy.java @@ -16,8 +16,8 @@ package com.fr.third.springframework.aop.framework; -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.ObjenesisStd; +import com.fr.third.org.objenesis.ObjenesisException; +import com.fr.third.org.objenesis.ObjenesisStd; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.fr.third.springframework.cglib.proxy.Callback; diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/Objenesis.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/Objenesis.java deleted file mode 100644 index 402c72ea2..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/Objenesis.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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.springframework.aop.objenesis; - -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; - -/** - * Common interface to all kind of Objenesis objects - * - * @author Henri Tremblay - */ -public interface Objenesis { - - /** - * Will create a new object without any constructor being called - * - * @param Type instantiated - * @param clazz Class to instantiate - * @return New instance of clazz - */ - T newInstance(Class clazz); - - /** - * 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 Type to instantiate - * @param clazz Class to instantiate - * @return Instantiator dedicated to the class - */ - ObjectInstantiator getInstantiatorOf(Class clazz); -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisBase.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisBase.java deleted file mode 100644 index c34690c95..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisBase.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * 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.springframework.aop.objenesis; - -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.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> 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>() : 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 newInstance(Class 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 ObjectInstantiator getInstantiatorOf(Class 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) instantiator; - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisException.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisException.java deleted file mode 100644 index 682c45562..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisException.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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.springframework.aop.objenesis; - -/** - * Exception thrown by Objenesis. It wraps any instantiation exceptions. Note that this exception is - * runtime to prevent having to catch it. - * - * @author Henri Tremblay - */ -public class ObjenesisException extends RuntimeException { - - private static final long serialVersionUID = -2677230016262426968L; - - /** - * @param msg Error message - */ - public ObjenesisException(String msg) { - super(msg); - } - - /** - * @param cause Wrapped exception. The message will be the one of the cause. - */ - public ObjenesisException(Throwable cause) { - super(cause); - } - - /** - * @param msg Error message - * @param cause Wrapped exception - */ - public ObjenesisException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisHelper.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisHelper.java deleted file mode 100644 index 3d0c81483..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisHelper.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * 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.springframework.aop.objenesis; - -import java.io.Serializable; - -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; - -/** - * Use Objenesis in a static way. It is strongly not recommended to use this class. - * - * @author Henri Tremblay - */ -public final class ObjenesisHelper { - - private static final Objenesis OBJENESIS_STD = new ObjenesisStd(); - - private static final Objenesis OBJENESIS_SERIALIZER = new ObjenesisSerializer(); - - private ObjenesisHelper() { - } - - /** - * Will create a new object without any constructor being called - * - * @param Type instantiated - * @param clazz Class to instantiate - * @return New instance of clazz - */ - public static T newInstance(Class clazz) { - return OBJENESIS_STD.newInstance(clazz); - } - - /** - * Will create an object just like it's done by ObjectInputStream.readObject (the default - * constructor of the first non serializable class will be called) - * - * @param Type instantiated - * @param clazz Class to instantiate - * @return New instance of clazz - */ - public static T newSerializableInstance(Class clazz) { - return (T) OBJENESIS_SERIALIZER.newInstance(clazz); - } - - /** - * 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 Type to instantiate - * @param clazz Class to instantiate - * @return Instantiator dedicated to the class - */ - public static ObjectInstantiator getInstantiatorOf(Class clazz) { - return OBJENESIS_STD.getInstantiatorOf(clazz); - } - - /** - * Same as {@link #getInstantiatorOf(Class)} but providing an instantiator emulating - * ObjectInputStream.readObject behavior. - * - * @see #newSerializableInstance(Class) - * @param Type to instantiate - * @param clazz Class to instantiate - * @return Instantiator dedicated to the class - */ - public static ObjectInstantiator getSerializableObjectInstantiatorOf(Class clazz) { - return OBJENESIS_SERIALIZER.getInstantiatorOf(clazz); - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisSerializer.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisSerializer.java deleted file mode 100644 index b300c9d15..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisSerializer.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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.springframework.aop.objenesis; - -import com.fr.third.springframework.aop.objenesis.strategy.SerializingInstantiatorStrategy; - -/** - * Objenesis implementation using the {@link SerializingInstantiatorStrategy}. - * - * @author Henri Tremblay - */ -public class ObjenesisSerializer extends ObjenesisBase { - - /** - * Default constructor using the {@link com.fr.third.springframework.aop.objenesis.strategy.SerializingInstantiatorStrategy} - */ - public ObjenesisSerializer() { - super(new SerializingInstantiatorStrategy()); - } - - /** - * Instance using the {@link com.fr.third.springframework.aop.objenesis.strategy.SerializingInstantiatorStrategy} with or without caching - * {@link com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator}s - * - * @param useCache If {@link com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator}s should be cached - */ - public ObjenesisSerializer(boolean useCache) { - super(new SerializingInstantiatorStrategy(), useCache); - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisStd.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisStd.java deleted file mode 100644 index e7c1d3493..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisStd.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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.springframework.aop.objenesis; - -import com.fr.third.springframework.aop.objenesis.strategy.StdInstantiatorStrategy; - -/** - * Objenesis implementation using the {@link com.fr.third.springframework.aop.objenesis.strategy.StdInstantiatorStrategy}. - * - * @author Henri Tremblay - */ -public class ObjenesisStd extends ObjenesisBase { - - /** - * Default constructor using the {@link com.fr.third.springframework.aop.objenesis.strategy.StdInstantiatorStrategy} - */ - public ObjenesisStd() { - super(new StdInstantiatorStrategy()); - } - - /** - * Instance using the {@link com.fr.third.springframework.aop.objenesis.strategy.StdInstantiatorStrategy} with or without - * caching {@link com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator}s - * - * @param useCache If {@link com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator}s should be cached - */ - public ObjenesisStd(boolean useCache) { - super(new StdInstantiatorStrategy(), useCache); - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/ObjectInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/ObjectInstantiator.java deleted file mode 100644 index c18b2fe1e..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/ObjectInstantiator.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator; - -/** - * Instantiates a new object. - * - * @author Leonardo Mesquita - */ -public interface ObjectInstantiator { - - /** - * Returns a new instance of an object. The returned object's class is defined by the - * implementation. - * - * @return A new instance of an object. - */ - T newInstance(); - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/SerializationInstantiatorHelper.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/SerializationInstantiatorHelper.java deleted file mode 100644 index 515b69cbe..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/SerializationInstantiatorHelper.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator; - -import java.io.Serializable; - -/** - * Helper for common serialization-compatible instantiation functions - * - * @author Leonardo Mesquita - */ -public class SerializationInstantiatorHelper { - - /** - * Returns the first non-serializable superclass of a given class. According to Java Object - * Serialization Specification, objects read from a stream are initialized by calling an - * accessible no-arg constructor from the first non-serializable superclass in the object's - * hierarchy, allowing the state of non-serializable fields to be correctly initialized. - * - * @param Type to instantiate - * @param type Serializable class for which the first non-serializable superclass is to be found - * @return The first non-serializable superclass of 'type'. - * @see Serializable - */ - public static Class getNonSerializableSuperClass(Class type) { - Class result = type; - while(Serializable.class.isAssignableFrom(result)) { - result = result.getSuperclass(); - if(result == null) { - throw new Error("Bad class hierarchy: No non-serializable parents"); - } - } - return result; - - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android10Instantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android10Instantiator.java deleted file mode 100644 index 5795e702b..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android10Instantiator.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.android; - -import java.io.ObjectInputStream; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiator for Android API level 10 and lover which creates objects without driving their - * constructors, using internal methods on the Dalvik implementation of - * {@link ObjectInputStream}. - * - * @author Piotr 'Qertoip' WĹ‚odarek - */ -@Instantiator(Typology.STANDARD) -public class Android10Instantiator implements ObjectInstantiator { - private final Class type; - private final Method newStaticMethod; - - public Android10Instantiator(Class type) { - this.type = type; - newStaticMethod = getNewStaticMethod(); - } - - public T newInstance() { - try { - return type.cast(newStaticMethod.invoke(null, type, Object.class)); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - - private static Method getNewStaticMethod() { - try { - Method newStaticMethod = ObjectInputStream.class.getDeclaredMethod( - "newInstance", Class.class, Class.class); - newStaticMethod.setAccessible(true); - return newStaticMethod; - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android17Instantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android17Instantiator.java deleted file mode 100644 index 36d9b8b0c..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android17Instantiator.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.android; - -import java.io.ObjectStreamClass; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiator for Android API level 11 to 17 which creates objects without driving their - * constructors, using internal methods on the Dalvik implementation of {@link ObjectStreamClass}. - * - * @author Ian Parkinson (Google Inc.) - */ -@Instantiator(Typology.STANDARD) -public class Android17Instantiator implements ObjectInstantiator { - private final Class type; - private final Method newInstanceMethod; - private final Integer objectConstructorId; - - public Android17Instantiator(Class type) { - this.type = type; - newInstanceMethod = getNewInstanceMethod(); - objectConstructorId = findConstructorIdForJavaLangObjectConstructor(); - } - - public T newInstance() { - try { - return type.cast(newInstanceMethod.invoke(null, type, objectConstructorId)); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - - private static Method getNewInstanceMethod() { - try { - Method newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod( - "newInstance", Class.class, Integer.TYPE); - newInstanceMethod.setAccessible(true); - return newInstanceMethod; - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } - - private static Integer findConstructorIdForJavaLangObjectConstructor() { - try { - Method newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod( - "getConstructorId", Class.class); - newInstanceMethod.setAccessible(true); - - return (Integer) newInstanceMethod.invoke(null, Object.class); - } - 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); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android18Instantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android18Instantiator.java deleted file mode 100644 index 81957ace2..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android18Instantiator.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.android; - -import java.io.ObjectStreamClass; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiator for Android API leve 18 and higher. Same as the version 17 but the - * newInstance now takes a long in parameter - * - * @author Henri Tremblay - */ -@Instantiator(Typology.STANDARD) -public class Android18Instantiator implements ObjectInstantiator { - private final Class type; - private final Method newInstanceMethod; - private final Long objectConstructorId; - - public Android18Instantiator(Class type) { - this.type = type; - newInstanceMethod = getNewInstanceMethod(); - objectConstructorId = findConstructorIdForJavaLangObjectConstructor(); - } - - public T newInstance() { - try { - return type.cast(newInstanceMethod.invoke(null, type, objectConstructorId)); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - - private static Method getNewInstanceMethod() { - try { - Method newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod("newInstance", - Class.class, Long.TYPE); - newInstanceMethod.setAccessible(true); - return newInstanceMethod; - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } - - private static Long findConstructorIdForJavaLangObjectConstructor() { - try { - Method newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod("getConstructorId", - Class.class); - newInstanceMethod.setAccessible(true); - - return (Long) newInstanceMethod.invoke(null, Object.class); - } - 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); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/AndroidSerializationInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/AndroidSerializationInstantiator.java deleted file mode 100644 index 6dd9a25d2..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/AndroidSerializationInstantiator.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.android; - -import java.io.ObjectStreamClass; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * {@link ObjectInstantiator} for Android which creates objects using the constructor from the first - * non-serializable parent class constructor, using internal methods on the Dalvik implementation of - * {@link ObjectStreamClass}. - * - * @author Ian Parkinson (Google Inc.) - */ -@Instantiator(Typology.SERIALIZATION) -public class AndroidSerializationInstantiator implements ObjectInstantiator { - private final Class type; - private final ObjectStreamClass objectStreamClass; - private final Method newInstanceMethod; - - public AndroidSerializationInstantiator(Class type) { - this.type = type; - newInstanceMethod = getNewInstanceMethod(); - Method m = null; - try { - m = ObjectStreamClass.class.getMethod("lookupAny", Class.class); - } catch (NoSuchMethodException e) { - throw new ObjenesisException(e); - } - try { - objectStreamClass = (ObjectStreamClass) m.invoke(null, type); - } catch (IllegalAccessException e) { - throw new ObjenesisException(e); - } catch (InvocationTargetException e) { - throw new ObjenesisException(e); - } - } - - public T newInstance() { - try { - return type.cast(newInstanceMethod.invoke(objectStreamClass, type)); - } - catch(IllegalAccessException e) { - throw new ObjenesisException(e); - } - catch(IllegalArgumentException e) { - throw new ObjenesisException(e); - } - catch(InvocationTargetException e) { - throw new ObjenesisException(e); - } - } - - private static Method getNewInstanceMethod() { - try { - Method newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod( - "newInstance", Class.class); - newInstanceMethod.setAccessible(true); - return newInstanceMethod; - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/annotations/Instantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/annotations/Instantiator.java deleted file mode 100644 index de8a7c8b0..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/annotations/Instantiator.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.annotations; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Denote that the class in an instantiator of a given type - * - * @author Henri Tremblay - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface Instantiator { - - /** - * @return type of instantiator - */ - Typology value(); -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/annotations/Typology.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/annotations/Typology.java deleted file mode 100644 index 2e2512768..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/annotations/Typology.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.annotations; - -/** - * Possible types of instantiator - * @author Henri Tremblay - */ -public enum Typology { - /** - * Mark an instantiator used for standard instantiation (not calling a constructor). - */ - STANDARD, - - /** - * Mark an instantiator used for serialization. - */ - SERIALIZATION, - - /** - * Mark an instantiator that doesn't behave like a {@link #STANDARD} nor a {@link #SERIALIZATION} (e.g. calls a constructor, fails - * all the time, etc.) - */ - NOT_COMPLIANT, - - /** - * No type specified on the instantiator class - */ - UNKNOWN -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/AccessibleInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/AccessibleInstantiator.java deleted file mode 100644 index 759538927..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/AccessibleInstantiator.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.basic; - -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by grabbing the no-args constructor, making it accessible and then calling - * Constructor.newInstance(). Although this still requires no-arg constructors, it can call - * non-public constructors (if the security manager allows it). - * - * @author Joe Walnes - * @see com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator - */ -@Instantiator(Typology.NOT_COMPLIANT) -public class AccessibleInstantiator extends ConstructorInstantiator { - - public AccessibleInstantiator(Class type) { - super(type); - if(constructor != null) { - constructor.setAccessible(true); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ConstructorInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ConstructorInstantiator.java deleted file mode 100644 index 5a7fbb0dd..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ConstructorInstantiator.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.basic; - -import java.lang.reflect.Constructor; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by grabbing the no args constructor and calling Constructor.newInstance(). - * This can deal with default public constructors, but that's about it. - * - * @author Joe Walnes - * @param Type instantiated - * @see ObjectInstantiator - */ -@Instantiator(Typology.NOT_COMPLIANT) -public class ConstructorInstantiator implements ObjectInstantiator { - - protected Constructor constructor; - - public ConstructorInstantiator(Class type) { - try { - constructor = type.getDeclaredConstructor((Class[]) null); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - - public T newInstance() { - try { - return constructor.newInstance((Object[]) null); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/FailingInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/FailingInstantiator.java deleted file mode 100644 index 9807425ed..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/FailingInstantiator.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.basic; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * The instantiator that always throws an exception. Mainly used for tests - * - * @author Henri Tremblay - */ -@Instantiator(Typology.NOT_COMPLIANT) -public class FailingInstantiator implements ObjectInstantiator { - - public FailingInstantiator(Class type) { - } - - /** - * @return Always throwing an exception - */ - public T newInstance() { - throw new ObjenesisException("Always failing"); - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/NewInstanceInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/NewInstanceInstantiator.java deleted file mode 100644 index d7e0c730d..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/NewInstanceInstantiator.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.basic; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * The simplest instantiator - simply calls Class.newInstance(). This can deal with default public - * constructors, but that's about it. - * - * @author Joe Walnes - * @see ObjectInstantiator - */ -@Instantiator(Typology.NOT_COMPLIANT) -public class NewInstanceInstantiator implements ObjectInstantiator { - - private final Class type; - - public NewInstanceInstantiator(Class type) { - this.type = type; - } - - public T newInstance() { - try { - return type.newInstance(); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/NullInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/NullInstantiator.java deleted file mode 100644 index 24960ab3c..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/NullInstantiator.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.basic; - -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * The instantiator that always return a null instance - * - * @author Henri Tremblay - */ -@Instantiator(Typology.NOT_COMPLIANT) -public class NullInstantiator implements ObjectInstantiator { - - public NullInstantiator(Class type) { - } - - /** - * @return Always null - */ - public T newInstance() { - return null; - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java deleted file mode 100644 index ee1aa4dc0..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java +++ /dev/null @@ -1,186 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.basic; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.NotSerializableException; -import java.io.ObjectInputStream; -import java.io.ObjectStreamClass; -import java.io.ObjectStreamConstants; -import java.io.Serializable; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by using a dummy input stream that always feeds data for an empty object of - * the same kind. NOTE: This instantiator may not work properly if the class being instantiated - * defines a "readResolve" method, since it may return objects that have been returned previously - * (i.e., there's no guarantee that the returned object is a new one), or even objects from a - * completely different class. - * - * @author Leonardo Mesquita - * @see com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator - */ -@Instantiator(Typology.SERIALIZATION) -public class ObjectInputStreamInstantiator implements ObjectInstantiator { - private static class MockStream extends InputStream { - - private int pointer; - private byte[] data; - private int sequence; - private static final int[] NEXT = new int[] {1, 2, 2}; - private byte[][] buffers; - - private final byte[] FIRST_DATA; - private static byte[] HEADER; - private static byte[] REPEATING_DATA; - - static { - initialize(); - } - - private static void initialize() { - try { - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - DataOutputStream dout = new DataOutputStream(byteOut); - dout.writeShort(ObjectStreamConstants.STREAM_MAGIC); - dout.writeShort(ObjectStreamConstants.STREAM_VERSION); - HEADER = byteOut.toByteArray(); - - byteOut = new ByteArrayOutputStream(); - dout = new DataOutputStream(byteOut); - - dout.writeByte(ObjectStreamConstants.TC_OBJECT); - dout.writeByte(ObjectStreamConstants.TC_REFERENCE); - dout.writeInt(ObjectStreamConstants.baseWireHandle); - REPEATING_DATA = byteOut.toByteArray(); - } - catch(IOException e) { - throw new Error("IOException: " + e.getMessage()); - } - - } - - public MockStream(Class clazz) { - this.pointer = 0; - this.sequence = 0; - this.data = HEADER; - - // (byte) TC_OBJECT - // (byte) TC_CLASSDESC - // (short length) - // (byte * className.length) - // (long)serialVersionUID - // (byte) SC_SERIALIZABLE - // (short)0 - // TC_ENDBLOCKDATA - // TC_NULL - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - DataOutputStream dout = new DataOutputStream(byteOut); - try { - dout.writeByte(ObjectStreamConstants.TC_OBJECT); - dout.writeByte(ObjectStreamConstants.TC_CLASSDESC); - dout.writeUTF(clazz.getName()); - dout.writeLong(ObjectStreamClass.lookup(clazz).getSerialVersionUID()); - dout.writeByte(ObjectStreamConstants.SC_SERIALIZABLE); - dout.writeShort((short) 0); // Zero fields - dout.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA); - dout.writeByte(ObjectStreamConstants.TC_NULL); - } - catch(IOException e) { - throw new Error("IOException: " + e.getMessage()); - } - this.FIRST_DATA = byteOut.toByteArray(); - buffers = new byte[][] {HEADER, FIRST_DATA, REPEATING_DATA}; - } - - private void advanceBuffer() { - pointer = 0; - sequence = NEXT[sequence]; - data = buffers[sequence]; - } - - @Override - public int read() throws IOException { - int result = data[pointer++]; - if(pointer >= data.length) { - advanceBuffer(); - } - - return result; - } - - @Override - public int available() throws IOException { - return Integer.MAX_VALUE; - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - int left = len; - int remaining = data.length - pointer; - - while(remaining <= left) { - System.arraycopy(data, pointer, b, off, remaining); - off += remaining; - left -= remaining; - advanceBuffer(); - remaining = data.length - pointer; - } - if(left > 0) { - System.arraycopy(data, pointer, b, off, left); - pointer += left; - } - - return len; - } - } - - private ObjectInputStream inputStream; - - public ObjectInputStreamInstantiator(Class clazz) { - if(Serializable.class.isAssignableFrom(clazz)) { - try { - this.inputStream = new ObjectInputStream(new MockStream(clazz)); - } - catch(IOException e) { - throw new Error("IOException: " + e.getMessage()); - } - } - else { - throw new ObjenesisException(new NotSerializableException(clazz + " not serializable")); - } - } - - @SuppressWarnings("unchecked") - public T newInstance() { - try { - return (T) inputStream.readObject(); - } - catch(ClassNotFoundException e) { - throw new Error("ClassNotFoundException: " + e.getMessage()); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java deleted file mode 100644 index 74d11c8f4..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.basic; - -import java.io.ObjectStreamClass; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by using reflection to make a call to private method - * ObjectStreamClass.newInstance, present in many JVM implementations. This instantiator will create - * classes in a way compatible with serialization, calling the first non-serializable superclass' - * no-arg constructor. - * - * @author Leonardo Mesquita - * @see ObjectInstantiator - * @see java.io.Serializable - */ -@Instantiator(Typology.SERIALIZATION) -public class ObjectStreamClassInstantiator implements ObjectInstantiator { - - private static Method newInstanceMethod; - - private static void initialize() { - if(newInstanceMethod == null) { - try { - newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod("newInstance"); - newInstanceMethod.setAccessible(true); - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } - } - - private final ObjectStreamClass objStreamClass; - - public ObjectStreamClassInstantiator(Class type) { - initialize(); - objStreamClass = ObjectStreamClass.lookup(type); - } - - @SuppressWarnings("unchecked") - public T newInstance() { - - try { - return (T) newInstanceMethod.invoke(objStreamClass); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ProxyingInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ProxyingInstantiator.java deleted file mode 100644 index 30f55ae59..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ProxyingInstantiator.java +++ /dev/null @@ -1,193 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.basic; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; -import com.fr.third.springframework.aop.objenesis.instantiator.util.ClassDefinitionUtils; - -import static com.fr.third.springframework.aop.objenesis.instantiator.util.ClassDefinitionUtils.*; - -/** - * This instantiator creates a class by dynamically extending it. It will skip the call to the parent constructor - * in the bytecode. So that the constructor is indeed not called but you however instantiate a child class, not - * the actual class. The class loader will normally throw a {@code VerifyError} is you do that. However, using - * {@code -Xverify:none} should make it work - * - * @author Henri Tremblay - */ -@Instantiator(Typology.STANDARD) -public class ProxyingInstantiator implements ObjectInstantiator { - - private static final int INDEX_CLASS_THIS = 1; - private static final int INDEX_CLASS_SUPERCLASS = 2; - private static final int INDEX_UTF8_CONSTRUCTOR_NAME = 3; - private static final int INDEX_UTF8_CONSTRUCTOR_DESC = 4; - private static final int INDEX_UTF8_CODE_ATTRIBUTE = 5; - private static final int INDEX_UTF8_CLASS = 7; - private static final int INDEX_UTF8_SUPERCLASS = 8; - - private static int CONSTANT_POOL_COUNT = 9; - - private static final byte[] CODE = { OPS_aload_0, OPS_return}; - private static final int CODE_ATTRIBUTE_LENGTH = 12 + CODE.length; - - private static final String SUFFIX = "$$$Objenesis"; - - private static final String CONSTRUCTOR_NAME = ""; - private static final String CONSTRUCTOR_DESC = "()V"; - - private final Class newType; - - public ProxyingInstantiator(Class type) { - - byte[] classBytes = writeExtendingClass(type, SUFFIX); - - try { - newType = ClassDefinitionUtils.defineClass(type.getName() + SUFFIX, classBytes, type.getClassLoader()); - } catch (Exception e) { - throw new ObjenesisException(e); - } - } - - @SuppressWarnings("unchecked") - public T newInstance() { - try { - return (T) newType.newInstance(); - } catch (InstantiationException e) { - throw new ObjenesisException(e); - } catch (IllegalAccessException e) { - throw new ObjenesisException(e); - } - } - - /** - * Will generate the bytes for a class extending the type passed in parameter. This class will - * 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 suffix) { - String parentClazz = 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 { - in = new DataOutputStream(bIn); - - in.write(MAGIC); - in.write(VERSION); - in.writeShort(CONSTANT_POOL_COUNT); - - // set all the constant pool here - - // 1. class - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_CLASS); - - // 2. super class - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_SUPERCLASS); - - // 3. default constructor name - in.writeByte(CONSTANT_Utf8); - in.writeUTF(CONSTRUCTOR_NAME); - - // 4. default constructor description - in.writeByte(CONSTANT_Utf8); - in.writeUTF(CONSTRUCTOR_DESC); - - // 5. Code - in.writeByte(CONSTANT_Utf8); - in.writeUTF("Code"); - - // 6. Class name - in.writeByte(CONSTANT_Utf8); - in.writeUTF("L" + clazz + ";"); - - // 7. Class name (again) - in.writeByte(CONSTANT_Utf8); - in.writeUTF(clazz); - - // 8. Superclass name - in.writeByte(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); - - // this class index in the constant pool - in.writeShort(INDEX_CLASS_THIS); - - // super class index in the constant pool - in.writeShort(INDEX_CLASS_SUPERCLASS); - - // interfaces implemented count (we have none) - in.writeShort(0); - - // fields count (we have none) - in.writeShort(0); - - // methods count (we have one: the default constructor) - in.writeShort(1); - - // default constructor method_info - in.writeShort(ACC_PUBLIC); - in.writeShort(INDEX_UTF8_CONSTRUCTOR_NAME); // index of the method name () - in.writeShort(INDEX_UTF8_CONSTRUCTOR_DESC); // index of the description - in.writeShort(1); // number of attributes: only one, the code - - // code attribute of the default constructor - in.writeShort(INDEX_UTF8_CODE_ATTRIBUTE); - in.writeInt(CODE_ATTRIBUTE_LENGTH); // attribute length - in.writeShort(1); // max_stack - in.writeShort(1); // max_locals - in.writeInt(CODE.length); // code length - in.write(CODE); - in.writeShort(0); // exception_table_length = 0 - in.writeShort(0); // attributes count = 0, no need to have LineNumberTable and LocalVariableTable - - // class attributes - in.writeShort(0); // none. No need to have a source file attribute - - - } catch (IOException e) { - throw new ObjenesisException(e); - } finally { - if(in != null) { - try { - in.close(); - } catch (IOException e) { - throw new ObjenesisException(e); - } - } - } - - return bIn.toByteArray(); - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJInstantiator.java deleted file mode 100644 index 9a35db494..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJInstantiator.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.gcj; - -import java.lang.reflect.InvocationTargetException; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by making a call to internal GCJ private methods. It is only supposed to - * work on GCJ JVMs. This instantiator will not call any constructors. - * - * @author Leonardo Mesquita - * @see com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator - */ -@Instantiator(Typology.STANDARD) -public class GCJInstantiator extends GCJInstantiatorBase { - public GCJInstantiator(Class type) { - super(type); - } - - @Override - public T newInstance() { - try { - return type.cast(newObjectMethod.invoke(dummyStream, type, Object.class)); - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(IllegalAccessException e) { - throw new ObjenesisException(e); - } - catch(InvocationTargetException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJInstantiatorBase.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJInstantiatorBase.java deleted file mode 100644 index 2390266f1..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJInstantiatorBase.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.gcj; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; - -/** - * Base class for GCJ-based instantiators. It initializes reflection access to method - * ObjectInputStream.newObject, as well as creating a dummy ObjectInputStream to be used as the - * "this" argument for the method. - * - * @author Leonardo Mesquita - */ -public abstract class GCJInstantiatorBase implements ObjectInstantiator { - static Method newObjectMethod = null; - static ObjectInputStream dummyStream; - - private static class DummyStream extends ObjectInputStream { - public DummyStream() throws IOException { - } - } - - private static void initialize() { - if(newObjectMethod == null) { - try { - newObjectMethod = ObjectInputStream.class.getDeclaredMethod("newObject", new Class[] { - Class.class, Class.class}); - newObjectMethod.setAccessible(true); - dummyStream = new DummyStream(); - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - catch(IOException e) { - throw new ObjenesisException(e); - } - } - } - - protected final Class type; - - public GCJInstantiatorBase(Class type) { - this.type = type; - initialize(); - } - - public abstract T newInstance(); -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJSerializationInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJSerializationInstantiator.java deleted file mode 100644 index 16a4d70ad..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJSerializationInstantiator.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.gcj; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.SerializationInstantiatorHelper; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by making a call to internal GCJ private methods. It is only supposed to - * work on GCJ JVMs. This instantiator will create classes in a way compatible with serialization, - * calling the first non-serializable superclass' no-arg constructor. - * - * @author Leonardo Mesquita - * @see com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator - */ -@Instantiator(Typology.SERIALIZATION) -public class GCJSerializationInstantiator extends GCJInstantiatorBase { - private Class superType; - - public GCJSerializationInstantiator(Class type) { - super(type); - this.superType = SerializationInstantiatorHelper.getNonSerializableSuperClass(type); - } - - @Override - public T newInstance() { - try { - return type.cast(newObjectMethod.invoke(dummyStream, type, superType)); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/perc/PercInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/perc/PercInstantiator.java deleted file mode 100644 index 894193b6a..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/perc/PercInstantiator.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.perc; - -import java.io.ObjectInputStream; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by making a call to internal Perc private methods. It is only supposed to - * work on Perc JVMs. This instantiator will not call any constructors. The code was provided by - * Aonix Perc support team. - * - * @author Henri Tremblay - * @see com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator - */ -@Instantiator(Typology.STANDARD) -public class PercInstantiator implements ObjectInstantiator { - - private final Method newInstanceMethod; - - private final Object[] typeArgs = new Object[] { null, Boolean.FALSE }; - - public PercInstantiator(Class type) { - - typeArgs[0] = type; - - try { - newInstanceMethod = ObjectInputStream.class.getDeclaredMethod("newInstance", Class.class, - Boolean.TYPE); - newInstanceMethod.setAccessible(true); - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } - - @SuppressWarnings("unchecked") - public T newInstance() { - try { - return (T) newInstanceMethod.invoke(null, typeArgs); - } catch (Exception e) { - throw new ObjenesisException(e); - } - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/perc/PercSerializationInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/perc/PercSerializationInstantiator.java deleted file mode 100644 index ea9ab3acd..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/perc/PercSerializationInstantiator.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.perc; - -import java.io.ObjectInputStream; -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by making a call to internal Perc private methods. It is only supposed to - * work on Perc JVMs. This instantiator will create classes in a way compatible with serialization, - * calling the first non-serializable superclass' no-arg constructor. - *

- * Based on code provided by Aonix but doesn't work right now - * - * @author Henri Tremblay - * @see com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator - */ -@Instantiator(Typology.SERIALIZATION) -public class PercSerializationInstantiator implements ObjectInstantiator { - - private Object[] typeArgs; - - private final Method newInstanceMethod; - - public PercSerializationInstantiator(Class type) { - - // Find the first unserializable parent class - Class unserializableType = type; - - while(Serializable.class.isAssignableFrom(unserializableType)) { - unserializableType = unserializableType.getSuperclass(); - } - - try { - // Get the special Perc method to call - Class percMethodClass = Class.forName("COM.newmonics.PercClassLoader.Method"); - - newInstanceMethod = ObjectInputStream.class.getDeclaredMethod("noArgConstruct", - new Class[] {Class.class, Object.class, percMethodClass}); - newInstanceMethod.setAccessible(true); - - // Create invoke params - Class percClassClass = Class.forName("COM.newmonics.PercClassLoader.PercClass"); - Method getPercClassMethod = percClassClass.getDeclaredMethod("getPercClass", Class.class); - Object someObject = getPercClassMethod.invoke(null, unserializableType); - Method findMethodMethod = someObject.getClass().getDeclaredMethod("findMethod", - new Class[] {String.class}); - Object percMethod = findMethodMethod.invoke(someObject, "()V"); - - typeArgs = new Object[] {unserializableType, type, percMethod}; - - } - 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); - } - } - - @SuppressWarnings("unchecked") - public T newInstance() { - try { - return (T) newInstanceMethod.invoke(null, typeArgs); - } - catch(IllegalAccessException e) { - throw new ObjenesisException(e); - } - catch(InvocationTargetException e) { - throw new ObjenesisException(e); - } - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/MagicInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/MagicInstantiator.java deleted file mode 100644 index 045716400..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/MagicInstantiator.java +++ /dev/null @@ -1,296 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.sun; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; -import com.fr.third.springframework.aop.objenesis.instantiator.util.ClassDefinitionUtils; - -import static com.fr.third.springframework.aop.objenesis.instantiator.util.ClassDefinitionUtils.*; - -/** - * This instantiator will correctly bypass the constructors by instantiating the class using the default - * constructor from Object. It will be allowed to do so by extending {@code MagicAccessorImpl} which prevents - * its children to be verified by the class loader - * - * @author Henri Tremblay - */ -@Instantiator(Typology.STANDARD) -public class MagicInstantiator implements ObjectInstantiator { - - private static final String MAGIC_ACCESSOR = getMagicClass(); - - private static final int INDEX_CLASS_THIS = 1; - private static final int INDEX_CLASS_SUPERCLASS = 2; - private static final int INDEX_UTF8_CONSTRUCTOR_NAME = 3; - private static final int INDEX_UTF8_CONSTRUCTOR_DESC = 4; - private static final int INDEX_UTF8_CODE_ATTRIBUTE = 5; - private static final int INDEX_UTF8_INSTANTIATOR_CLASS = 7; - private static final int INDEX_UTF8_SUPERCLASS = 8; - private static final int INDEX_CLASS_INTERFACE = 9; - private static final int INDEX_UTF8_INTERFACE = 10; - private static final int INDEX_UTF8_NEWINSTANCE_NAME = 11; - private static final int INDEX_UTF8_NEWINSTANCE_DESC = 12; - private static final int INDEX_METHODREF_OBJECT_CONSTRUCTOR = 13; - private static final int INDEX_CLASS_OBJECT = 14; - private static final int INDEX_UTF8_OBJECT = 15; - private static final int INDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTOR = 16; - private static final int INDEX_CLASS_TYPE = 17; - private static final int INDEX_UTF8_TYPE = 18; - - 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 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 int NEWINSTANCE_CODE_ATTRIBUTE_LENGTH = 12 + NEWINSTANCE_CODE.length; - - private static final String CONSTRUCTOR_NAME = ""; - private static final String CONSTRUCTOR_DESC = "()V"; - - private ObjectInstantiator instantiator; - - public MagicInstantiator(Class type) { - instantiator = newInstantiatorOf(type); - } - - /** - * Get the underlying instantiator. - * - * {@link MagicInstantiator} is a wrapper around another object - * which implements {@link ObjectInstantiator} interface. - * This method exposes that instantiator. - * - * @return the underlying instantiator - */ - public ObjectInstantiator getInstantiator() { - return instantiator; - } - - private ObjectInstantiator newInstantiatorOf(Class type) { - String suffix = type.getSimpleName(); - String className = getClass().getName() + "$$$" + suffix; - - Class> clazz = getExistingClass(getClass().getClassLoader(), className); - - if(clazz == null) { - byte[] classBytes = writeExtendingClass(type, className); - - try { - clazz = ClassDefinitionUtils.defineClass(className, classBytes, getClass().getClassLoader()); - } catch (Exception e) { - throw new ObjenesisException(e); - } - } - - try { - return clazz.newInstance(); - } catch (InstantiationException e) { - throw new ObjenesisException(e); - } catch (IllegalAccessException e) { - throw new ObjenesisException(e); - } - } - - /** - * Will generate the bytes for a class extending the type passed in parameter. This class will - * only have an empty default constructor - * - * @param type type to extend - * @param className name of the wrapped instantiator class - * @return the byte for the class - * @throws ObjenesisException is something goes wrong - */ - private byte[] writeExtendingClass(Class type, String className) { - String clazz = classNameToInternalClassName(className); - - 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(MAGIC); - in.write(VERSION); - in.writeShort(CONSTANT_POOL_COUNT); - - // set all the constant pool here - - // 1. class - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_INSTANTIATOR_CLASS); - - // 2. super class - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_SUPERCLASS); - - // 3. default constructor name - in.writeByte(CONSTANT_Utf8); - in.writeUTF(CONSTRUCTOR_NAME); - - // 4. default constructor description - in.writeByte(CONSTANT_Utf8); - in.writeUTF(CONSTRUCTOR_DESC); - - // 5. Code - in.writeByte(CONSTANT_Utf8); - in.writeUTF("Code"); - - // 6. Class name - in.writeByte(CONSTANT_Utf8); - in.writeUTF("L" + clazz + ";"); - - // 7. Class name (again) - in.writeByte(CONSTANT_Utf8); - in.writeUTF(clazz); - - // 8. Superclass name - in.writeByte(CONSTANT_Utf8); -// in.writeUTF("java/lang/Object"); - in.writeUTF(MAGIC_ACCESSOR); - - // 9. ObjectInstantiator interface - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_INTERFACE); - - // 10. ObjectInstantiator name - in.writeByte(CONSTANT_Utf8); - in.writeUTF(ObjectInstantiator.class.getName().replace('.', '/')); - - // 11. newInstance name - in.writeByte(CONSTANT_Utf8); - in.writeUTF("newInstance"); - - // 12. newInstance desc - in.writeByte(CONSTANT_Utf8); - in.writeUTF("()Ljava/lang/Object;"); - - // 13. Methodref to the Object constructor - in.writeByte(CONSTANT_Methodref); - in.writeShort(INDEX_CLASS_OBJECT); - in.writeShort(INDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTOR); - - // 14. Object class - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_OBJECT); - - // 15. Object class name - in.writeByte(CONSTANT_Utf8); - in.writeUTF("java/lang/Object"); - - // 16. Default constructor name and type - in.writeByte(CONSTANT_NameAndType); - in.writeShort(INDEX_UTF8_CONSTRUCTOR_NAME); - in.writeShort(INDEX_UTF8_CONSTRUCTOR_DESC); - - // 17. Type to instantiate class - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_TYPE); - - // 18. Type to instantiate name - in.writeByte(CONSTANT_Utf8); - in.writeUTF(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); - - // this class index in the constant pool - in.writeShort(INDEX_CLASS_THIS); - - // super class index in the constant pool - in.writeShort(INDEX_CLASS_SUPERCLASS); - - // interfaces implemented count (we have none) - in.writeShort(1); - in.writeShort(INDEX_CLASS_INTERFACE); - - // fields count (we have none) - in.writeShort(0); - - // method count (we have two: the default constructor and newInstance) - in.writeShort(2); - - // default constructor method_info - in.writeShort(ACC_PUBLIC); - in.writeShort(INDEX_UTF8_CONSTRUCTOR_NAME); // index of the method name () - in.writeShort(INDEX_UTF8_CONSTRUCTOR_DESC); // index of the description - in.writeShort(1); // number of attributes: only one, the code - - // code attribute of the default constructor - in.writeShort(INDEX_UTF8_CODE_ATTRIBUTE); - in.writeInt(CONSTRUCTOR_CODE_ATTRIBUTE_LENGTH); // attribute length - in.writeShort(0); // max_stack - in.writeShort(1); // max_locals - in.writeInt(CONSTRUCTOR_CODE.length); // code length - in.write(CONSTRUCTOR_CODE); - in.writeShort(0); // exception_table_length = 0 - in.writeShort(0); // attributes count = 0, no need to have LineNumberTable and LocalVariableTable - - // newInstance method_info - in.writeShort(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 - - // code attribute of newInstance - in.writeShort(INDEX_UTF8_CODE_ATTRIBUTE); - in.writeInt(NEWINSTANCE_CODE_ATTRIBUTE_LENGTH); // attribute length - in.writeShort(2); // max_stack - in.writeShort(1); // max_locals - in.writeInt(NEWINSTANCE_CODE.length); // code length - in.write(NEWINSTANCE_CODE); - in.writeShort(0); // exception_table_length = 0 - in.writeShort(0); // attributes count = 0, no need to have LineNumberTable and LocalVariableTable - - // class attributes - in.writeShort(0); // none. No need to have a source file attribute - - } catch (IOException e) { - throw new ObjenesisException(e); - } finally { - if(in != null) { - try { - in.close(); - } catch (IOException e) { - throw new ObjenesisException(e); - } - } - } - - return bIn.toByteArray(); - } - - public T newInstance() { - return instantiator.newInstance(); - } - - private static String getMagicClass() { - try { - Class.forName("sun.reflect.MagicAccessorImpl", false, MagicInstantiator.class.getClassLoader()); - return "sun/reflect/MagicAccessorImpl"; - } catch (ClassNotFoundException e) { - return "jdk/internal/reflect/MagicAccessorImpl"; - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactoryHelper.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactoryHelper.java deleted file mode 100644 index 994c6a52a..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactoryHelper.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.sun; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; - - -/** - * Helper methods providing access to {@link sun.reflect.ReflectionFactory} via reflection, for use - * by the {@link ObjectInstantiator}s that use it. - * - * @author Henri Tremblay - */ -@SuppressWarnings("restriction") -class SunReflectionFactoryHelper { - - @SuppressWarnings("unchecked") - public static Constructor newConstructorForSerialization(Class type, - Constructor constructor) { - Class reflectionFactoryClass = getReflectionFactoryClass(); - Object reflectionFactory = createReflectionFactory(reflectionFactoryClass); - - Method newConstructorForSerializationMethod = getNewConstructorForSerializationMethod( - reflectionFactoryClass); - - try { - return (Constructor) newConstructorForSerializationMethod.invoke( - reflectionFactory, type, constructor); - } - catch(IllegalArgumentException e) { - throw new ObjenesisException(e); - } - catch(IllegalAccessException e) { - throw new ObjenesisException(e); - } - catch(InvocationTargetException e) { - throw new ObjenesisException(e); - } - } - - private static Class getReflectionFactoryClass() { - try { - return Class.forName("sun.reflect.ReflectionFactory"); - } - catch(ClassNotFoundException e) { - throw new ObjenesisException(e); - } - } - - private static Object createReflectionFactory(Class reflectionFactoryClass) { - try { - Method method = reflectionFactoryClass.getDeclaredMethod( - "getReflectionFactory"); - return method.invoke(null); - } - 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); - } - } - - private static Method getNewConstructorForSerializationMethod(Class reflectionFactoryClass) { - try { - return reflectionFactoryClass.getDeclaredMethod( - "newConstructorForSerialization", Class.class, Constructor.class); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java deleted file mode 100644 index 761001115..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.sun; - -import java.lang.reflect.Constructor; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates an object, WITHOUT calling it's constructor, using internal - * sun.reflect.ReflectionFactory - a class only available on JDK's that use Sun's 1.4 (or later) - * Java implementation. This is the best way to instantiate an object without any side effects - * caused by the constructor - however it is not available on every platform. - * - * @author Joe Walnes - * @see ObjectInstantiator - */ -@Instantiator(Typology.STANDARD) -public class SunReflectionFactoryInstantiator implements ObjectInstantiator { - - private final Constructor mungedConstructor; - - public SunReflectionFactoryInstantiator(Class type) { - Constructor javaLangObjectConstructor = getJavaLangObjectConstructor(); - mungedConstructor = SunReflectionFactoryHelper.newConstructorForSerialization( - type, javaLangObjectConstructor); - mungedConstructor.setAccessible(true); - } - - public T newInstance() { - try { - return mungedConstructor.newInstance((Object[]) null); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - - private static Constructor getJavaLangObjectConstructor() { - try { - return Object.class.getConstructor((Class[]) null); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java deleted file mode 100644 index acb3463de..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.sun; - -import java.io.NotSerializableException; -import java.lang.reflect.Constructor; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.SerializationInstantiatorHelper; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates an object using internal sun.reflect.ReflectionFactory - a class only available on - * JDK's that use Sun's 1.4 (or later) Java implementation. This instantiator will create classes in - * a way compatible with serialization, calling the first non-serializable superclass' no-arg - * constructor. This is the best way to instantiate an object without any side effects caused by the - * constructor - however it is not available on every platform. - * - * @author Leonardo Mesquita - * @see ObjectInstantiator - */ -@Instantiator(Typology.SERIALIZATION) -public class SunReflectionFactorySerializationInstantiator implements ObjectInstantiator { - - private final Constructor mungedConstructor; - - public SunReflectionFactorySerializationInstantiator(Class type) { - Class nonSerializableAncestor = SerializationInstantiatorHelper - .getNonSerializableSuperClass(type); - - Constructor nonSerializableAncestorConstructor; - try { - nonSerializableAncestorConstructor = nonSerializableAncestor - .getDeclaredConstructor((Class[]) null); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(new NotSerializableException(type+" has no suitable superclass constructor")); - } - - mungedConstructor = SunReflectionFactoryHelper.newConstructorForSerialization( - type, nonSerializableAncestorConstructor); - mungedConstructor.setAccessible(true); - } - - public T newInstance() { - try { - return mungedConstructor.newInstance((Object[]) null); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java deleted file mode 100644 index 003902491..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.sun; - -import sun.misc.Unsafe; -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; -import com.fr.third.springframework.aop.objenesis.instantiator.util.UnsafeUtils; - -import java.lang.reflect.Field; - -/** - * Instantiates an object, WITHOUT calling it's constructor, using - * {@code sun.misc.Unsafe.allocateInstance()}. Unsafe and its methods are implemented by most - * modern JVMs. - * - * @author Henri Tremblay - * @see ObjectInstantiator - */ -@SuppressWarnings("restriction") -@Instantiator(Typology.STANDARD) -public class UnsafeFactoryInstantiator implements ObjectInstantiator { - - private final Unsafe unsafe; - private final Class type; - - public UnsafeFactoryInstantiator(Class type) { - this.unsafe = UnsafeUtils.getUnsafe(); // retrieve it to fail right away at instantiator creation if not there - this.type = type; - } - - public T newInstance() { - try { - return type.cast(unsafe.allocateInstance(type)); - } catch (InstantiationException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/util/ClassDefinitionUtils.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/util/ClassDefinitionUtils.java deleted file mode 100644 index 898fe4cc3..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/util/ClassDefinitionUtils.java +++ /dev/null @@ -1,195 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.util; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; - -import java.io.BufferedOutputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.ProtectionDomain; - -import sun.misc.Unsafe; - -/** - * Helper class for ProxyObjectInstantiator. We can see the details of a class specification - * here - * - * @author Henri Tremblay - */ -public final class ClassDefinitionUtils { - - public static final byte OPS_aload_0 = 42; - public static final byte OPS_invokespecial = -73; // has two bytes parameters - public static final byte OPS_return = -79; - public static final byte OPS_new = -69; - public static final byte OPS_dup = 89; - public static final byte OPS_areturn = -80; - - public static final int CONSTANT_Utf8 = 1; - public static final int CONSTANT_Integer = 3; - public static final int CONSTANT_Float = 4; - public static final int CONSTANT_Long = 5; - public static final int CONSTANT_Double = 6; - public static final int CONSTANT_Class = 7; - public static final int CONSTANT_String = 8; - public static final int CONSTANT_Fieldref = 9; - public static final int CONSTANT_Methodref = 10; - public static final int CONSTANT_InterfaceMethodref = 11; - public static final int CONSTANT_NameAndType = 12; - public static final int CONSTANT_MethodHandle = 15; - public static final int CONSTANT_MethodType = 16; - public static final int CONSTANT_InvokeDynamic = 18; - - public static final int ACC_PUBLIC = 0x0001; // Declared public; may be accessed from outside its package. - public static final int ACC_FINAL = 0x0010; // Declared final; no subclasses allowed. - public static final int ACC_SUPER = 0x0020; // Treat superclass methods specially when invoked by the invokespecial instruction. - public static final int ACC_INTERFACE = 0x0200; // Is an interface, not a class. - public static final int ACC_ABSTRACT = 0x0400; // Declared abstract; must not be instantiated. - public static final int ACC_SYNTHETIC = 0x1000; // Declared synthetic; not present in the source code. - public static final int ACC_ANNOTATION = 0x2000; // Declared as an annotation type. - public static final int ACC_ENUM = 0x4000; // Declared as an enum type. - - public static final byte[] MAGIC = { (byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe }; - public static final byte[] VERSION = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x31 }; // minor_version, major_version (Java 5) - - private ClassDefinitionUtils() { } - -// private static Method DEFINE_CLASS; - private static final ProtectionDomain PROTECTION_DOMAIN; - - static { - PROTECTION_DOMAIN = AccessController.doPrivileged(new PrivilegedAction() { - public ProtectionDomain run() { - return ClassDefinitionUtils.class.getProtectionDomain(); - } - }); - } - - /** - * Define a class in the provided class loader from the array of bytes. Inspired by cglib - * ReflectUtils.defineClass - * - * @param type of the class returned - * @param className class name in the format com.fr.third.springframework.aop.objenesis.MyClass - * @param b bytes representing the class - * @param loader the class loader where the class will be loaded - * @return the newly loaded class - * @throws Exception whenever something goes wrong - */ - @SuppressWarnings("unchecked") - public static Class defineClass(String className, byte[] b, ClassLoader loader) - throws Exception { - Class c = (Class) UnsafeUtils.getUnsafe().defineClass(className, b, 0, b.length, loader, PROTECTION_DOMAIN); - // Force static initializers to run. - Class.forName(className, true, loader); - return c; - } - - /** - * Read the bytes of a class from the classpath - * - * @param className full class name including the package - * @return the bytes representing the class - * @throws IllegalArgumentException if the class is longer than 2500 bytes - * @throws IOException if we fail to read the class - */ - public static byte[] readClass(String className) throws IOException { - // convert to a resource - className = classNameToResource(className); - - byte[] b = new byte[2500]; // I'm assuming that I'm reading class that are not too big - - int length; - - InputStream in = ClassDefinitionUtils.class.getClassLoader().getResourceAsStream(className); - try { - length = in.read(b); - } - finally { - in.close(); - } - - if(length >= 2500) { - throw new IllegalArgumentException("The class is longer that 2500 bytes which is currently unsupported"); - } - - byte[] copy = new byte[length]; - System.arraycopy(b, 0, copy, 0, length); - return copy; - } - - /** - * Write all class bytes to a file. - * - * @param fileName file where the bytes will be written - * @param bytes bytes representing the class - * @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 { - out.write(bytes); - } - finally { - out.close(); - } - } - - /** - * Will convert a class name to its name in the class definition format (e.g {@code com.fr.third.springframework.aop.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.springframework.aop.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 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 Class getExistingClass(ClassLoader classLoader, String className) { - try { - return (Class) Class.forName(className, true, classLoader); - } - catch (ClassNotFoundException e) { - return null; - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/util/UnsafeUtils.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/util/UnsafeUtils.java deleted file mode 100644 index 091bb3ea5..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/util/UnsafeUtils.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.springframework.aop.objenesis.instantiator.util; - -import java.lang.reflect.Field; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; - -import sun.misc.Unsafe; - -/** - * Helper class basically allowing to get access to {@code sun.misc.Unsafe} - * - * @author Henri Tremblay - */ -public final class UnsafeUtils { - - private static final Unsafe unsafe; - - static { - Field f; - try { - f = Unsafe.class.getDeclaredField("theUnsafe"); - } catch (NoSuchFieldException e) { - throw new ObjenesisException(e); - } - f.setAccessible(true); - try { - unsafe = (Unsafe) f.get(null); - } catch (IllegalAccessException e) { - throw new ObjenesisException(e); - } - } - - private UnsafeUtils() {} - - public static Unsafe getUnsafe() { - return unsafe; - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/BaseInstantiatorStrategy.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/BaseInstantiatorStrategy.java deleted file mode 100644 index 87826b5c4..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/BaseInstantiatorStrategy.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * 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.springframework.aop.objenesis.strategy; - -/** - * Base {@link InstantiatorStrategy} class basically. Only implements {@link InstantiatorStrategy} - * - * @author Henri Tremblay - */ -public abstract class BaseInstantiatorStrategy implements InstantiatorStrategy { - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/InstantiatorStrategy.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/InstantiatorStrategy.java deleted file mode 100644 index 75b4ccebe..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/InstantiatorStrategy.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * 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.springframework.aop.objenesis.strategy; - -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; - -/** - * Defines a strategy to determine the best instantiator for a class. - * - * @author Henri Tremblay - */ -public interface InstantiatorStrategy { - - /** - * Create a dedicated instantiator for the given class - * - * @param Type to instantiate - * @param type Class that will be instantiated - * @return Dedicated instantiator - */ - ObjectInstantiator newInstantiatorOf(Class type); -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/PlatformDescription.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/PlatformDescription.java deleted file mode 100644 index 36a9f5623..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/PlatformDescription.java +++ /dev/null @@ -1,198 +0,0 @@ -/** - * 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.springframework.aop.objenesis.strategy; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; - -import java.lang.reflect.Field; - -/** - * List of constants describing the currently used platform. - * - * @author Henri Tremblay - */ -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"; - - /** JVM_NAME prefix for Java HotSpot */ - public static final String HOTSPOT = "Java HotSpot"; - - /** - * JVM_NAME prefix for Java HotSpot - * - * @deprecated Use {@link #HOTSPOT} instead - */ - @Deprecated - public static final String SUN = HOTSPOT; - - /** JVM_NAME prefix for the OpenJDK */ - public static final String OPENJDK = "OpenJDK"; - - /** JVM_NAME prefix for Aonix PERC */ - public static final String PERC = "PERC"; - - /** JVM_NAME prefix for Dalvik/Android */ - public static final String DALVIK = "Dalvik"; - - /** Java specification version */ - public static final String SPECIFICATION_VERSION = System - .getProperty("java.specification.version"); - - /** JVM version */ - public static final String VM_VERSION = System.getProperty("java.runtime.version"); - - /** JVM version */ - public static final String VM_INFO = System.getProperty("java.vm.info"); - - /** VM vendor version */ - public static final String VENDOR_VERSION = System.getProperty("java.vm.version"); - - /** VM vendor name */ - public static final String VENDOR = System.getProperty("java.vm.vendor"); - - /** JVM name */ - public static final String JVM_NAME = System.getProperty("java.vm.name"); - - /** Android version. Will be 0 for none android platform */ - public static final int ANDROID_VERSION = getAndroidVersion(); - - /** Flag telling if this version of Android is based on the OpenJDK */ - public static final boolean IS_ANDROID_OPENJDK = getIsAndroidOpenJDK(); - - /** Google App Engine version or null is we are not on GAE */ - public static final String GAE_VERSION = getGaeRuntimeVersion(); - - /** - * Describes the platform. Outputs Java version and vendor. - * - * @return Description of the current platform - */ - public static String describePlatform() { - String desc = "Java " + SPECIFICATION_VERSION + " (" - + "VM vendor name=\"" + VENDOR + "\", " - + "VM vendor version=" + VENDOR_VERSION + ", " - + "JVM name=\"" + JVM_NAME + "\", " - + "JVM version=" + VM_VERSION + ", " - + "JVM info=" + VM_INFO; - - // Add the API level is it's an Android platform - int androidVersion = ANDROID_VERSION; - if(androidVersion != 0) { - desc += ", API level=" + ANDROID_VERSION; - } - desc += ")"; - - return desc; - } - - /** - * Check if the current JVM is of the type passed in parameter. Normally, this will be a constant - * from this class. We basically do - * System.getProperty("java.vm.name").startWith(name). - * - * @param name jvm name we are looking for - * @return if it's the requested JVM - */ - public static boolean isThisJVM(String name) { - return JVM_NAME.startsWith(name); - } - - /** - * Check if this JVM is an Android JVM based on OpenJDK. - * - * @return if it's an Android version based on the OpenJDK. Will return false if this JVM isn't an Android JVM at all - */ - public static boolean isAndroidOpenJDK() { - return IS_ANDROID_OPENJDK; - } - - private static boolean getIsAndroidOpenJDK() { - if(getAndroidVersion() == 0) { - return false; // Not android at all - } - // Sadly, Android N is still API 23. So we can't base ourselves on the API level to know if it is an OpenJDK - // version or not - String bootClasspath = System.getProperty("java.boot.class.path"); - return bootClasspath != null && bootClasspath.toLowerCase().contains("core-oj.jar"); - } - - public static boolean isGoogleAppEngine() { - return GAE_VERSION != null; - } - - private static String getGaeRuntimeVersion() { - return System.getProperty("com.google.appengine.runtime.version"); - } - - private static int getAndroidVersion() { - if(!isThisJVM(DALVIK)) { - return 0; - } - return getAndroidVersion0(); - } - - private static int getAndroidVersion0() { - Class clazz; - try { - clazz = Class.forName("android.os.Build$VERSION"); - } - catch(ClassNotFoundException e) { - throw new ObjenesisException(e); - } - Field field; - try { - field = clazz.getField("SDK_INT"); - } - catch(NoSuchFieldException e) { - // Might be a really old API (before 4), go for SDK - return getOldAndroidVersion(clazz); - } - int version; - try { - version = (Integer) field.get(null); - } - catch(IllegalAccessException e) { - throw new RuntimeException(e); - } - return version; - } - - private static int getOldAndroidVersion(Class versionClass) { - Field field; - try { - field = versionClass.getField("SDK"); - } - catch(NoSuchFieldException e) { - throw new ObjenesisException(e); - } - String version; - try { - version = (String) field.get(null); - } - catch(IllegalAccessException e) { - throw new RuntimeException(e); - } - return Integer.parseInt(version); - } - - private PlatformDescription() { - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/SerializingInstantiatorStrategy.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/SerializingInstantiatorStrategy.java deleted file mode 100644 index c11f19368..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/SerializingInstantiatorStrategy.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * 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.springframework.aop.objenesis.strategy; - -import java.io.NotSerializableException; -import java.io.Serializable; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.android.AndroidSerializationInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.basic.ObjectInputStreamInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.basic.ObjectStreamClassInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.gcj.GCJSerializationInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.perc.PercSerializationInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.sun.SunReflectionFactorySerializationInstantiator; - -import static com.fr.third.springframework.aop.objenesis.strategy.PlatformDescription.*; - -/** - * Guess the best serializing instantiator for a given class. The returned instantiator will - * instantiate classes like the genuine java serialization framework (the constructor of the first - * not serializable class will be called). Currently, the selection doesn't depend on the class. It - * relies on the - *
    - *
  • JVM version
  • - *
  • JVM vendor
  • - *
  • JVM vendor version
  • - *
- * However, instantiators are stateful and so dedicated to their class. - * - * @author Henri Tremblay - * @see ObjectInstantiator - */ -public class SerializingInstantiatorStrategy extends BaseInstantiatorStrategy { - - /** - * Return an {@link ObjectInstantiator} allowing to create instance following the java - * serialization framework specifications. - * - * @param type Class to instantiate - * @return The ObjectInstantiator for the class - */ - public ObjectInstantiator newInstantiatorOf(Class type) { - if(!Serializable.class.isAssignableFrom(type)) { - throw new ObjenesisException(new NotSerializableException(type+" not serializable")); - } - 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 SunReflectionFactorySerializationInstantiator(type); - } - else if(JVM_NAME.startsWith(DALVIK)) { - if(PlatformDescription.isAndroidOpenJDK()) { - return new ObjectStreamClassInstantiator(type); - } - return new AndroidSerializationInstantiator(type); - } - else if(JVM_NAME.startsWith(GNU)) { - return new GCJSerializationInstantiator(type); - } - else if(JVM_NAME.startsWith(PERC)) { - return new PercSerializationInstantiator(type); - } - - return new SunReflectionFactorySerializationInstantiator(type); - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/SingleInstantiatorStrategy.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/SingleInstantiatorStrategy.java deleted file mode 100644 index 3352fdac8..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/SingleInstantiatorStrategy.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * 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.springframework.aop.objenesis.strategy; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -/** - * Strategy returning only one instantiator type. Useful if you know on which JVM Objenesis - * will be used and want to specify it explicitly. - * - * @author Henri Tremblay - */ -public class SingleInstantiatorStrategy implements InstantiatorStrategy { - - private Constructor constructor; - - /** - * Create a strategy that will return always the same instantiator type. We assume this instantiator - * has one constructor taking the class to instantiate in parameter. - * - * @param the type we want to instantiate - * @param instantiator the instantiator type - */ - public > SingleInstantiatorStrategy(Class instantiator) { - try { - constructor = instantiator.getConstructor(Class.class); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } - - /** - * Return an instantiator for the wanted type and of the one and only type of instantiator returned by this - * class. - * - * @param the type we want to instantiate - * @param type Class to instantiate - * @return The ObjectInstantiator for the class - */ - @SuppressWarnings("unchecked") - public ObjectInstantiator newInstantiatorOf(Class type) { - try { - return (ObjectInstantiator) constructor.newInstance(type); - } catch (InstantiationException e) { - throw new ObjenesisException(e); - } catch (IllegalAccessException e) { - throw new ObjenesisException(e); - } catch (InvocationTargetException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/StdInstantiatorStrategy.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/StdInstantiatorStrategy.java deleted file mode 100644 index 2e1f3680c..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/StdInstantiatorStrategy.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * 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.springframework.aop.objenesis.strategy; - -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.android.Android10Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.android.Android17Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.android.Android18Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.basic.AccessibleInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.basic.ObjectInputStreamInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.gcj.GCJInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.perc.PercInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.sun.SunReflectionFactoryInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.sun.UnsafeFactoryInstantiator; - -import java.io.Serializable; - -import static com.fr.third.springframework.aop.objenesis.strategy.PlatformDescription.*; - -/** - * Guess the best instantiator for a given class. The instantiator will instantiate the class - * without calling any constructor. Currently, the selection doesn't depend on the class. It relies - * on the - *
    - *
  • JVM version
  • - *
  • JVM vendor
  • - *
  • JVM vendor version
  • - *
- * However, instantiators are stateful and so dedicated to their class. - * - * @author Henri Tremblay - * @see ObjectInstantiator - */ -public class StdInstantiatorStrategy extends BaseInstantiatorStrategy { - - /** - * Return an {@link ObjectInstantiator} allowing to create instance without any constructor being - * called. - * - * @param type Class to instantiate - * @return The ObjectInstantiator for the class - */ - public ObjectInstantiator newInstantiatorOf(Class 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 AccessibleInstantiator(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); - } - else if(PlatformDescription.isThisJVM(DALVIK)) { - if(PlatformDescription.isAndroidOpenJDK()) { - // Starting at Android N which is based on OpenJDK - return new UnsafeFactoryInstantiator(type); - } - if(ANDROID_VERSION <= 10) { - // Android 2.3 Gingerbread and lower - return new Android10Instantiator(type); - } - if(ANDROID_VERSION <= 17) { - // Android 3.0 Honeycomb to 4.2 Jelly Bean - return new Android17Instantiator(type); - } - // Android 4.3 until Android N - return new Android18Instantiator(type); - } - else if(PlatformDescription.isThisJVM(JROCKIT)) { - // JRockit is compliant with HotSpot - return new SunReflectionFactoryInstantiator(type); - } - else if(PlatformDescription.isThisJVM(GNU)) { - return new GCJInstantiator(type); - } - else if(PlatformDescription.isThisJVM(PERC)) { - return new PercInstantiator(type); - } - - // Fallback instantiator, should work with most modern JVM - return new UnsafeFactoryInstantiator(type); - - } -} diff --git a/fine-spring/src/com/fr/third/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java b/fine-spring/src/com/fr/third/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java index 3bc04abee..8944ad9b3 100644 --- a/fine-spring/src/com/fr/third/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java +++ b/fine-spring/src/com/fr/third/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java @@ -22,7 +22,7 @@ import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; -import com.fr.third.springframework.aop.objenesis.ObjenesisStd; +import com.fr.third.org.objenesis.ObjenesisStd; import org.aopalliance.intercept.MethodInterceptor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;