public static void throwRandomRuntimeException() { String random = "planb:" + UUID.randomUUID().toString(); RuntimeException[] exceptions = new RuntimeException[]{ new IllegalStateException("This is a test exception because the sate " + random), new IllegalArgumentException("Wrong argument test exception" + random), new RuntimeException("This is a test exception " + random), new IllegalSelectorException(), new IndexOutOfBoundsException("A test index exception " + random), new ClassCastException("A test class cast exception " + random), new NoSuchElementException("A test no such element exception " + random), new MalformedParameterizedTypeException(), new BufferOverflowException(), new EmptyStackException(), new NullPointerException("This is not a real nullpointer " + random), new SecurityException("This is not a real security exception " + random), new ArithmeticException("This is not a real arithmetic exception " + random), new IllegalThreadStateException("This is a test exception with threads " + random), new IllegalCharsetNameException("Charset is wrong test exception " + random), new IllegalMonitorStateException("This is a test exception with illegal monitor " + random)}; throw exceptions[new Random().nextInt(exceptions.length)]; }
Type resolve() { GenericDeclaration d = decl; while (d != null) { for (TypeVariable t : d.getTypeParameters()) { if (t.getName().equals(name)) { return t; } } d = getParent(d); } throw new MalformedParameterizedTypeException(); }
public Type getGenericSuperclass() throws GenericSignatureFormatError, TypeNotPresentException, MalformedParameterizedTypeException { String tmp; if (isInterface() || ((tmp = getCanonicalName()) != null && tmp.equals("java.lang.Object")) || isPrimitive()) { return null; } if (isArray()) { return (Type) OBJECT_CLASS; } Class<?> clazz = getSuperclass(); if (clazz.getTypeParameters().length == 0) { return (Type) clazz; } return getCache().getGenericSuperclass(); }
public Type[] getLowerBounds() throws TypeNotPresentException, MalformedParameterizedTypeException { if (lowerBounds == null) { if (wildCardTypeBillet.boundsType == false) { int l = wildCardTypeBillet.bounds.length; lowerBounds = new Type[l]; for (int i = 0; i < l; i++) { // it can be InterimTypeVariable or InterimParameterizedType or InterimClassType. // The MalformedParameterizedTypeException and TypeNotPresentException should be raised here if it needs. try { lowerBounds[i] = AuxiliaryCreator.createTypeArg(wildCardTypeBillet.bounds[i], this.startPoint); } catch(ClassNotFoundException e) { throw new TypeNotPresentException(((InterimClassType)wildCardTypeBillet.bounds[i]).classTypeName.substring(1).replace('/', '.'), e); // ClassNotFoundException may appear here only for InterimClassType, see AuxiliaryCreator.createTypeArg. } } } else { lowerBounds = new Type[0]; } } return (Type[])this.lowerBounds.clone(); }
public Type[] getUpperBounds() throws TypeNotPresentException, MalformedParameterizedTypeException { if (upperBounds == null) { if (wildCardTypeBillet.boundsType) { int l = wildCardTypeBillet.bounds.length; upperBounds = new Type[l]; for (int i = 0; i < l; i++) { // it can be InterimTypeVariable or InterimParameterizedType or InterimClassType. // The MalformedParameterizedTypeException and TypeNotPresentException should be raised here if it needs. try { upperBounds[i] = AuxiliaryCreator.createTypeArg(wildCardTypeBillet.bounds[i], this.startPoint); } catch(ClassNotFoundException e) { throw new TypeNotPresentException(((InterimClassType)wildCardTypeBillet.bounds[i]).classTypeName.substring(1).replace('/', '.'), e); // ClassNotFoundException may appear here only for InterimClassType, see AuxiliaryCreator.createTypeArg. } } } else { upperBounds = new Type[1]; upperBounds[0] = (Type) Object.class; } } return (Type[])this.upperBounds.clone(); }
public ParameterizedTypeImpl(Class<?> rawType, Type ownerType, Type[] actualTypeArguments) { this.rawType = rawType; this.ownerType = ownerType == null ? rawType.getDeclaringClass() : ownerType; this.actualTypeArguments = actualTypeArguments; TypeVariable<?>[] formals = rawType.getTypeParameters(); if (formals.length != actualTypeArguments.length) { throw new MalformedParameterizedTypeException(); } }
private void validateConstructorArguments() { TypeVariable/*<?>*/[] formals = rawType.getTypeParameters(); // check correct arity of actual type args if (formals.length != actualTypeArguments.length){ throw new MalformedParameterizedTypeException(); } for (int i = 0; i < actualTypeArguments.length; i++) { // check actuals against formals' bounds } }
private void validateConstructorArguments() { TypeVariable<?>[] formals = rawType.getTypeParameters(); // check correct arity of actual type args if (formals.length != actualTypeArguments.length){ throw new MalformedParameterizedTypeException(); } for (int i = 0; i < actualTypeArguments.length; i++) { // check actuals against formals' bounds } }
private void validateConstructorArguments() { TypeVariable/*<?>*/[] formals = rawType.getTypeParameters(); // check correct arity of actual type args if (formals.length != actualTypeArguments.length) { throw new MalformedParameterizedTypeException(); } /* for (int i = 0; i < actualTypeArguments.length; i++) { // check actuals against formals' bounds } */ }
private void validateConstructorArguments() { TypeVariable/* <?> */[] formals = rawType.getTypeParameters(); // check correct arity of actual type args if (formals.length != actualTypeArguments.length) { throw new MalformedParameterizedTypeException(); } for (int i = 0; i < actualTypeArguments.length; i++) { // check actuals against formals' bounds } }
private ParameterizedTypeImpl(Class<?> rawType, Type[] actualTypeArguments) { this.actualTypeArguments = actualTypeArguments; this.rawType = rawType; ownerType = rawType.getDeclaringClass(); TypeVariable<?>[] formals = rawType.getTypeParameters(); if (formals.length != actualTypeArguments.length) { throw new MalformedParameterizedTypeException(); } }
/** * java.lang.reflect.MalformedParameterizedTypeException#MalformedParameterizedTypeException() */ public void test_Constructor() throws Exception { Constructor<MalformedParameterizedTypeException> ctor = MalformedParameterizedTypeException.class .getDeclaredConstructor(); assertNotNull("Parameterless constructor does not exist.", ctor); assertTrue("Constructor is not protected", Modifier.isPublic(ctor .getModifiers())); assertNotNull(ctor.newInstance()); }
private void validateConstructorArguments() { @SuppressWarnings("rawtypes") TypeVariable[] arrayOfTypeVariable=this.rawType.getTypeParameters(); if(arrayOfTypeVariable.length != this.actualTypeArguments.length) { throw new MalformedParameterizedTypeException(); } // for(int i=0; i < this.actualTypeArguments.length; i++); }
private void validateConstructorArguments() { TypeVariable/*<?>*/[] formals = rawType.getTypeParameters(); // check correct arity of actual type args if (formals.length != actualTypeArguments.length) { throw new MalformedParameterizedTypeException(); } for (int i = 0; i < actualTypeArguments.length; i++) { // check actuals against formals' bounds } }
/** * @tests java.lang.reflect.MalformedParameterizedTypeException#MalformedParameterizedTypeException() */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "Since this constructor is never invoked, this test only verifies its existence.", method = "MalformedParameterizedTypeException", args = {} ) public void test_Constructor() throws Exception { Constructor<MalformedParameterizedTypeException> ctor = MalformedParameterizedTypeException.class .getDeclaredConstructor(); assertNotNull("Parameterless constructor does not exist.", ctor); assertTrue("Constructor is not protected", Modifier.isPublic(ctor .getModifiers())); assertNotNull(ctor.newInstance()); }
/** * Extract the generic type from the given Class object. * @param clazz the Class to check * @param source the expected raw source type (can be {@code null}) * @param typeIndex the index of the actual type argument * @param nestingLevel the nesting level of the target type * @param currentLevel the current nested level * @return the generic type as Class, or {@code null} if none */ private static Class<?> extractTypeFromClass(Class<?> clazz, Class<?> source, int typeIndex, Map<TypeVariable, Type> typeVariableMap, Map<Integer, Integer> typeIndexesPerLevel, int nestingLevel, int currentLevel) { if (clazz.getName().startsWith("java.util.")) { return null; } if (clazz.getSuperclass() != null && isIntrospectionCandidate(clazz.getSuperclass())) { try { return extractType(clazz.getGenericSuperclass(), source, typeIndex, typeVariableMap, typeIndexesPerLevel, nestingLevel, currentLevel); } catch (MalformedParameterizedTypeException ex) { // from getGenericSuperclass() - ignore and continue with interface introspection } } Type[] ifcs = clazz.getGenericInterfaces(); if (ifcs != null) { for (Type ifc : ifcs) { Type rawType = ifc; if (ifc instanceof ParameterizedType) { rawType = ((ParameterizedType) ifc).getRawType(); } if (rawType instanceof Class && isIntrospectionCandidate((Class) rawType)) { return extractType(ifc, source, typeIndex, typeVariableMap, typeIndexesPerLevel, nestingLevel, currentLevel); } } } return null; }
public Type[] getGenericInterfaces() throws GenericSignatureFormatError, TypeNotPresentException, MalformedParameterizedTypeException { if (isArray()) { return new Type[]{CLONEABLE_CLASS, SERIALIZABLE_CLASS}; } if (isPrimitive()) { return new Type[0]; } return (Type[])getCache().getGenericInterfaces().clone(); }
/** * @tests java.lang.reflect.MalformedParameterizedTypeException# * MalformedParameterizedTypeException() */ @Test public void testMalformedParameterizedTypeException() { MalformedParameterizedTypeException e = new MalformedParameterizedTypeException(); assertNotNull(e); assertNull(e.getMessage()); }