-
Notifications
You must be signed in to change notification settings - Fork 429
Closed
Description
FWIW @smillst I have encountered a similar error that I can file a new bug if you like and or maybe there is a way to annotate the "sneak throw" technique.
/**
* An error friendly {@link Function} for converting properties.
*
* @param <T> input type.
* @param <R> output type.
* @param <E> error type.
*/
public interface PropertyFunction<T extends @Nullable Object, R extends @Nullable Object, E extends Exception>
extends Function<T, R> {
@Override
default R apply(T t) {
try {
return _apply(t);
}
catch (Exception e) {
// the error happens below here.
sneakyThrow(e);
throw new RuntimeException(e);
}
}
/**
* Apply that throws error.
* @param t input
* @return output
* @throws E if an error happened in function.
*/
public R _apply(T t) throws E;
@SuppressWarnings("unchecked")
private static <E extends Throwable> void sneakyThrow(final Throwable x) throws E {
throw (E) x;
}
}[type.arguments.not.inferred] Could not infer type arguments for PropertyFunction.sneakyThrow
unsatisfiable constraint: @UnknownInitialization @Nullable RuntimeException</*Type args not initialized*/> <: @Initialized @NonNull Throwable
I'm not really sure how to properly annotate or suppress the warning (edit I had the suppress in the wrong place so that is why I could not suppress).
EDIT when I suppress the warning I get:
error: StructuralEqualityComparer: unexpected combination: type: [DECLARED class org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedDeclaredType] Object supertype: [TYPEVAR class org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedTypeVariable] R extends Object
Originally posted by @agentgt in #6629 (comment)
alexvas