File tree Expand file tree Collapse file tree 3 files changed +18
-8
lines changed
blackbox-test-inject/src/main/java/org/example/myapp/r4j
inject-generator/src/main/java/io/avaje/inject/generator Expand file tree Collapse file tree 3 files changed +18
-8
lines changed Original file line number Diff line number Diff line change 11package org .example .myapp .r4j ;
22
3- import io .avaje .inject .Component ;
43import org .example .myapp .resilience4j .MyRetry ;
54
5+ import io .avaje .inject .Component ;
6+
67@ Component
78public class MyExample {
89
910 public int barfCounter ;
1011 public int retryWithFallbackCounter ;
1112
1213 @ MyRetry
13- public void doingItWithRetry () {
14+ public void doingItWithRetry () throws Throwable , IllegalStateException {
1415 barfCounter ++;
1516 throw new IllegalArgumentException ("no" );
1617 }
Original file line number Diff line number Diff line change @@ -181,22 +181,25 @@ void writeArgs(Append writer) {
181181 writer .append (" return call.finalResult();" ).eol ();
182182 }
183183
184- writeThrowsCatch (writer );
185184 writer .append (" } catch (RuntimeException ex) {" ).eol ();
186185 writer .append (" ex.addSuppressed(new InvocationException(\" %s proxy threw exception\" ));" , simpleName ).eol ();
187186 writer .append (" throw ex;" ).eol ();
188- writer .append (" } catch (Throwable t) {" ).eol ();
189- writer .append (" throw new InvocationException(\" %s proxy threw exception\" , t);" , simpleName ).eol ();
187+ writeThrowsCatch (writer );
188+ if (thrownTypes .stream ().map (Object ::toString ).noneMatch ("java.lang.Throwable" ::equals )) {
189+ writer .append (" } catch (Throwable t) {" ).eol ();
190+ writer .append (" throw new InvocationException(\" %s proxy threw exception\" , t);" , simpleName ).eol ();
191+ }
190192 writer .append (" }" ).eol ();
191193 }
192194
193195 private void writeThrowsCatch (Append writer ) {
194-
195- if (thrownTypes .isEmpty ()) {
196+ final var types = new ArrayList <>(thrownTypes );
197+ types .removeIf (ProcessingContext ::isUncheckedException );
198+ if (types .isEmpty ()) {
196199 return ;
197200 }
198201 writer .append (" } catch (" );
199- thrownTypes .stream ()
202+ types .stream ()
200203 .map (Object ::toString )
201204 .map (Util ::shortName )
202205 .collect (collectingAndThen (joining (" | " ), writer ::append ))
Original file line number Diff line number Diff line change @@ -156,6 +156,12 @@ static Element asElement(TypeMirror returnType) {
156156 return wrapper == null ? CTX .get ().typeUtils .asElement (returnType ) : element (wrapper );
157157 }
158158
159+ static boolean isUncheckedException (TypeMirror returnType ) {
160+ final var types = CTX .get ().typeUtils ;
161+ final var runtime = element ("java.lang.RuntimeException" ).asType ();
162+ return types .isSubtype (returnType , runtime );
163+ }
164+
159165 static void addModule (String moduleFullName ) {
160166 if (moduleFullName != null ) {
161167 CTX .get ().uniqueModuleNames .add (moduleFullName );
You can’t perform that action at this time.
0 commit comments