Error and runtime exception should be propagated instead of being wrapped in isSubstitutable
Remi Forax
forax at univ-mlv.fr
Thu Jan 31 11:28:58 UTC 2019
Hi all,
i was testing this code
public class SubstituableTest {
static value class Link {
private final int value;
private final Object next;
public Link(int value, Object next) {
this.value = value;
this.next = next;
}
static Object times(int count) {
return IntStream.range(0, count).boxed().reduce(null, (acc, index) -> new Link(index, acc), (l1, l2) -> { throw null; });
}
}
public static void main(String[] args) {
var l = Link.times(1_000);
//System.out.println(l == l);
System.out.println(ValueBootstrapMethods.isSubstitutable(l, l));
}
}
and currently, it recreates a linked list of errors because errors are wrapped instead of being propagated
I believe the bug is in this code:
try {
Class<?> type = a.getClass().isValue() ? a.getClass().asValueType() : a.getClass();
return (boolean) substitutableInvoker(type).invoke(a, b);
} catch (Throwable e) {
if (VERBOSE) e.printStackTrace();
throw new InternalError(e);
}
it should be:
try {
Class<?> type = a.getClass().isValue() ? a.getClass().asValueType() : a.getClass();
return (boolean) substitutableInvoker(type).invoke(a, b);
} catch(Error | Runtime e) {
throw e;
} catch (Throwable e) {
if (VERBOSE) e.printStackTrace();
throw new InternalError(e);
}
regards,
Rémi
More information about the valhalla-dev
mailing list