Skip to content

Commit

Permalink
GROOVY-11293: ensure isVargsMethod initialized before return
Browse files Browse the repository at this point in the history
3_0_X backport
  • Loading branch information
eric-milles committed Jan 22, 2024
1 parent b9b321a commit 557a196
Show file tree
Hide file tree
Showing 28 changed files with 252 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public abstract class GeneratedMetaMethod extends MetaMethod {
private final Class returnType;

public GeneratedMetaMethod(String name, CachedClass declaringClass, Class returnType, Class[] parameters) {
super(parameters);
this.name = name;
this.declaringClass = declaringClass;
this.returnType = returnType;
nativeParamTypes = parameters;
}

public int getModifiers() {
Expand Down
286 changes: 130 additions & 156 deletions src/main/java/org/codehaus/groovy/reflection/ParameterTypes.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import java.lang.reflect.Modifier;

public abstract class NumberNumberMetaMethod extends CallSiteAwareMetaMethod {
private static final CachedClass NUMBER_CLASS = ReflectionCache.getCachedClass(Number.class);
private static final CachedClass [] NUMBER_CLASS_ARR = new CachedClass[] { NUMBER_CLASS };
private static final CachedClass NUMBER_CLASS = ReflectionCache.getCachedClass(Number.class);
private static final CachedClass[] NUMBER_CLASS_ARR = {NUMBER_CLASS};

protected NumberNumberMetaMethod() {
parameterTypes = NUMBER_CLASS_ARR;
setParametersTypes(NUMBER_CLASS_ARR);
}

public int getModifiers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
package org.codehaus.groovy.runtime.dgmimpl.arrays;

public abstract class ArrayGetAtMetaMethod extends ArrayMetaMethod {

protected ArrayGetAtMetaMethod() {
parameterTypes = INTEGER_CLASS_ARR;
setParametersTypes(INTEGER_CLASS_ARR);
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import java.lang.reflect.Modifier;

public abstract class ArrayMetaMethod extends CallSiteAwareMetaMethod {
protected static final CachedClass INTEGER_CLASS = ReflectionCache.getCachedClass(Integer.class);
protected static final CachedClass[] INTEGER_CLASS_ARR = new CachedClass[]{INTEGER_CLASS};
protected static final CachedClass INTEGER_CLASS = ReflectionCache.getCachedClass(Integer.class);
protected static final CachedClass[] INTEGER_CLASS_ARR = {INTEGER_CLASS};

protected static int normaliseIndex(int i, int size) {
int temp = i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@
*/
package org.codehaus.groovy.runtime.dgmimpl.arrays;

import org.codehaus.groovy.reflection.CachedClass;

import static org.codehaus.groovy.reflection.ReflectionCache.OBJECT_CLASS;

public abstract class ArrayPutAtMetaMethod extends ArrayMetaMethod {

private static final CachedClass[] PARAM_TYPES = {INTEGER_CLASS, OBJECT_CLASS};

protected ArrayPutAtMetaMethod() {
setParametersTypes(PARAM_TYPES);
}

@Override
public String getName() {
return "putAt";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;

public class BooleanArrayGetAtMetaMethod extends ArrayGetAtMetaMethod {
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(boolean[].class);
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(boolean[].class);

public Class getReturnType() {
return Boolean.class;
}

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;

public class BooleanArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass OBJECT_CLASS = ReflectionCache.OBJECT_CLASS;
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(boolean[].class);
private static final CachedClass[] PARAM_CLASS_ARR = new CachedClass[]{INTEGER_CLASS, OBJECT_CLASS};

public BooleanArrayPutAtMetaMethod() {
parameterTypes = PARAM_CLASS_ARR;
}
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(boolean[].class);

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;

public class ByteArrayGetAtMetaMethod extends ArrayGetAtMetaMethod {
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(byte[].class);
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(byte[].class);

public Class getReturnType() {
return Byte.class;
}

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;

public class ByteArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass OBJECT_CLASS = ReflectionCache.OBJECT_CLASS;
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(byte[].class);
private static final CachedClass[] PARAM_CLASS_ARR = new CachedClass[]{INTEGER_CLASS, OBJECT_CLASS};

public ByteArrayPutAtMetaMethod() {
parameterTypes = PARAM_CLASS_ARR;
}
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(byte[].class);

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;

public class CharacterArrayGetAtMetaMethod extends ArrayGetAtMetaMethod {
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(char[].class);
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(char[].class);

public Class getReturnType() {
return Character.class;
}

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,10 @@
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;

public class CharacterArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass OBJECT_CLASS = ReflectionCache.OBJECT_CLASS;
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(char[].class);
private static final CachedClass[] PARAM_CLASS_ARR = new CachedClass[]{INTEGER_CLASS, OBJECT_CLASS};

public CharacterArrayPutAtMetaMethod() {
parameterTypes = PARAM_CLASS_ARR;
}
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(char[].class);

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;

public class DoubleArrayGetAtMetaMethod extends ArrayGetAtMetaMethod {
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(double[].class);
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(double[].class);

public Class getReturnType() {
return Double.class;
}

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,10 @@
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;

public class DoubleArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass OBJECT_CLASS = ReflectionCache.OBJECT_CLASS;
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(double[].class);
private static final CachedClass[] PARAM_CLASS_ARR = new CachedClass[]{INTEGER_CLASS, OBJECT_CLASS};

public DoubleArrayPutAtMetaMethod() {
parameterTypes = PARAM_CLASS_ARR;
}
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(double[].class);

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;

public class FloatArrayGetAtMetaMethod extends ArrayGetAtMetaMethod {
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(float[].class);
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(float[].class);

public Class getReturnType() {
return Float.class;
}

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,10 @@
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;

public class FloatArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass OBJECT_CLASS = ReflectionCache.OBJECT_CLASS;
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(float[].class);
private static final CachedClass[] PARAM_CLASS_ARR = new CachedClass[]{INTEGER_CLASS, OBJECT_CLASS};

public FloatArrayPutAtMetaMethod() {
parameterTypes = PARAM_CLASS_ARR;
}
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(float[].class);

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;

public class IntegerArrayGetAtMetaMethod extends ArrayGetAtMetaMethod {
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(int[].class);
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(int[].class);

public Class getReturnType() {
return Integer.class;
}

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,10 @@
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;

public class IntegerArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass OBJECT_CLASS = ReflectionCache.OBJECT_CLASS;
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(int[].class);
private static final CachedClass[] PARAM_CLASS_ARR = new CachedClass[]{INTEGER_CLASS, OBJECT_CLASS};

public IntegerArrayPutAtMetaMethod() {
parameterTypes = PARAM_CLASS_ARR;
}
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(int[].class);

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;

public class LongArrayGetAtMetaMethod extends ArrayGetAtMetaMethod {
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(long[].class);
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(long[].class);

public Class getReturnType() {
return Long.class;
}

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,10 @@
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;

public class LongArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass OBJECT_CLASS = ReflectionCache.OBJECT_CLASS;
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(long[].class);
private static final CachedClass[] PARAM_CLASS_ARR = new CachedClass[]{INTEGER_CLASS, OBJECT_CLASS};

public LongArrayPutAtMetaMethod() {
parameterTypes = PARAM_CLASS_ARR;
}
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(long[].class);

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
import groovy.lang.MetaClassImpl;
import groovy.lang.MetaMethod;
import org.codehaus.groovy.reflection.CachedClass;
import org.codehaus.groovy.reflection.ReflectionCache;
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;

import static org.codehaus.groovy.reflection.ReflectionCache.OBJECT_ARRAY_CLASS;

public class ObjectArrayGetAtMetaMethod extends ArrayGetAtMetaMethod {
private static final CachedClass OBJECT_ARR_CLASS = ReflectionCache.OBJECT_ARRAY_CLASS;

public Class getReturnType() {
return Object.class;
}

public final CachedClass getDeclaringClass() {
return OBJECT_ARR_CLASS;
return OBJECT_ARRAY_CLASS;
}

public Object invoke(Object object, Object[] arguments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,16 @@
import groovy.lang.MetaClassImpl;
import groovy.lang.MetaMethod;
import org.codehaus.groovy.reflection.CachedClass;
import org.codehaus.groovy.reflection.ReflectionCache;
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;

public class ObjectArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass OBJECT_CLASS = ReflectionCache.getCachedClass(Object.class);
private static final CachedClass OBJECT_ARR_CLASS = ReflectionCache.OBJECT_ARRAY_CLASS;
private static final CachedClass[] PARAM_CLASS_ARR = new CachedClass[]{INTEGER_CLASS, OBJECT_CLASS};
import static org.codehaus.groovy.reflection.ReflectionCache.OBJECT_ARRAY_CLASS;

public ObjectArrayPutAtMetaMethod() {
parameterTypes = PARAM_CLASS_ARR;
}
public class ObjectArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {

public final CachedClass getDeclaringClass() {
return OBJECT_ARR_CLASS;
return OBJECT_ARRAY_CLASS;
}

public Object invoke(Object object, Object[] arguments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;

public class ShortArrayGetAtMetaMethod extends ArrayGetAtMetaMethod {
private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(short[].class);
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(short[].class);

public Class getReturnType() {
return Short.class;
}

public final CachedClass getDeclaringClass() {
return ARR_CLASS;
return ARRAY_CLASS;
}

public Object invoke(Object object, Object[] args) {
Expand Down
Loading

0 comments on commit 557a196

Please sign in to comment.