cstamas commented on code in PR #1910:
URL: https://github.com/apache/maven/pull/1910#discussion_r1842178580
##########
impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java:
##########
@@ -1733,12 +1734,50 @@ ModelSource resolveReactorModel(String groupId, String
artifactId, String versio
return null;
}
- private <T> T cache(String groupId, String artifactId, String version,
String tag, Supplier<T> supplier) {
- return cache.computeIfAbsent(groupId, artifactId, version, tag,
supplier);
+ @FunctionalInterface
+ private interface ThrowingSupplier<T, E extends Exception> {
+ T get() throws E;
+ }
+
+ private static class ThrowingSupplierWrapper<T, E extends Exception>
implements Supplier<T> {
+ private final ThrowingSupplier<T, E> throwingSupplier;
+
+ private ThrowingSupplierWrapper(ThrowingSupplier<T, E>
throwingSupplier) {
+ this.throwingSupplier = throwingSupplier;
+ }
+
+ @Override
+ public T get() {
+ try {
+ return throwingSupplier.get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static <T, E extends Exception> T process(
+ ThrowingSupplier<T, E> throwingSupplier,
Function<Supplier<T>, T> consumer) throws E {
+ try {
+ return consumer.apply(new
ThrowingSupplierWrapper<>(throwingSupplier));
+ } catch (RuntimeException e) {
+ if (e.getClass().equals(RuntimeException.class) &&
e.getCause() != null) {
+ throw (E) e.getCause();
+ } else {
+ throw e;
+ }
+ }
+ }
+ }
+
+ private <T, E extends Exception> T cache(
+ String groupId, String artifactId, String version, String tag,
ThrowingSupplier<T, E> supplier)
+ throws E {
+ return ThrowingSupplierWrapper.process(
+ supplier, s -> cache.computeIfAbsent(groupId, artifactId,
version, tag, s));
}
Review Comment:
IMO, the latest push is quite sensible. Also, have to add "boilerplate code
wanted to avoid" vs all the changes revealed just by the compiler as exception
when from unchecked to checked... which one is worth more for you?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]