private static void checkParameterOneOf( ErrorReporter errors, Parameter parameter, Collection<Class<? extends Parameter>> allowedParameterClasses) { for (Class<? extends Parameter> paramClass : allowedParameterClasses) { if (paramClass.isAssignableFrom(parameter.getClass())) { return; } } // If we get here, none matched errors.throwIllegalArgument("Illegal parameter type: %s", parameter); }
/** * Returns successfully if the field is valid, otherwise throws an exception via its {@link * ErrorReporter} parameter describing validation failures for the timer declaration. */ private static void validateTimerField( ErrorReporter errors, Map<String, TimerDeclaration> declarations, String id, Field field) { if (declarations.containsKey(id)) { errors.throwIllegalArgument( "Duplicate %s \"%s\", used on both of [%s] and [%s]", DoFn.TimerId.class.getSimpleName(), id, field.toString(), declarations.get(id).field().toString()); } Class<?> timerSpecRawType = field.getType(); if (!(timerSpecRawType.equals(TimerSpec.class))) { errors.throwIllegalArgument( "%s annotation on non-%s field [%s]", DoFn.TimerId.class.getSimpleName(), TimerSpec.class.getSimpleName(), field.toString()); } if (!Modifier.isFinal(field.getModifiers())) { errors.throwIllegalArgument( "Non-final field %s annotated with %s. Timer declarations must be final.", field.toString(), DoFn.TimerId.class.getSimpleName()); } }
private static Map<String, DoFnSignature.FieldAccessDeclaration> analyzeFieldAccessDeclaration( ErrorReporter errors, Class<?> fnClazz) { Map<String, FieldAccessDeclaration> fieldAccessDeclarations = new HashMap<>(); for (Field field : declaredFieldsWithAnnotation(DoFn.FieldAccess.class, fnClazz, DoFn.class)) { field.setAccessible(true); DoFn.FieldAccess fieldAccessAnnotation = field.getAnnotation(DoFn.FieldAccess.class); if (!Modifier.isFinal(field.getModifiers())) { errors.throwIllegalArgument( "Non-final field %s annotated with %s. Field access declarations must be final.", field.toString(), DoFn.FieldAccess.class.getSimpleName()); continue; } Class<?> fieldAccessRawType = field.getType(); if (!fieldAccessRawType.equals(FieldAccessDescriptor.class)) { errors.throwIllegalArgument( "Field %s annotated with %s, but the value was not of type %s", field.toString(), DoFn.FieldAccess.class.getSimpleName(), FieldAccessDescriptor.class.getSimpleName()); } fieldAccessDeclarations.put( fieldAccessAnnotation.value(), FieldAccessDeclaration.create(fieldAccessAnnotation.value(), field)); } return fieldAccessDeclarations; }
formatType(new TypeDescriptor<BoundedWindow>() {}), formatType(new TypeDescriptor<RestrictionTracker<?, ?>>() {})); paramErrors.throwIllegalArgument( "%s is not a valid context parameter. Should be one of %s", formatType(paramT), allowedParamTypes);
processElementErrors.throwIllegalArgument( "Splittable, but does not define the following required methods: %s", missingRequiredMethods);
errors.throwIllegalArgument( "Duplicate %s \"%s\", used on both of [%s] and [%s]", DoFn.StateId.class.getSimpleName(), errors.throwIllegalArgument( "%s annotation on non-%s field [%s] that has class %s", DoFn.StateId.class.getSimpleName(), errors.throwIllegalArgument( "Non-final field %s annotated with %s. State declarations must be final.", field.toString(), DoFn.StateId.class.getSimpleName());
public void checkNotNull(Object value, String message, Object... args) { if (value == null) { throwIllegalArgument(message, args); } } }
public void checkArgument(boolean condition, String message, Object... args) { if (!condition) { throwIllegalArgument(message, args); } }