Skip to content

Commit eb51187

Browse files
authored
Adding NoSuchMethodError to catch blocks (#2719)
### Summary The UIAutomation tests failed due to uncaught NoSuchMethodErrors. The methods I added as a part of my Baggage PRs do have catch blocks meant for this purpose, but they were catching a generic exception (which NoSuchMethodError does not fall into).
1 parent 3273fa3 commit eb51187

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

common4j/src/main/com/microsoft/identity/common/java/opentelemetry/BaggageExtension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static Scope makeBaggageCurrent(final Baggage baggage) {
5555
return SpanExtension.NoopScope.INSTANCE;
5656
}
5757
return baggage.storeInContext(Context.current()).makeCurrent();
58-
} catch (final Exception e) {
58+
} catch (final Exception | NoSuchMethodError e) {
5959
Logger.error(TAG + ":makeBaggageCurrent", "Failed to make baggage current", e);
6060
return SpanExtension.NoopScope.INSTANCE;
6161
}
@@ -69,7 +69,7 @@ public static Scope makeBaggageCurrent(final Baggage baggage) {
6969
public static Baggage fromContext(final Context context) {
7070
try {
7171
return Baggage.fromContext(context);
72-
} catch (final Exception e) {
72+
} catch (final Exception | NoSuchMethodError e) {
7373
Logger.error(TAG + ":fromContext", "Failed to get baggage from context", e);
7474
return new NoopBaggage();
7575
}

common4j/src/main/com/microsoft/identity/common/java/opentelemetry/SpanExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static Scope makeCurrentSpan(@NonNull final Span span) {
100100
public static Span fromContext(@NonNull final Context context) {
101101
try {
102102
return Span.fromContext(context);
103-
} catch (final Exception error) {
103+
} catch (final Exception | NoSuchMethodError error) {
104104
Logger.error(TAG + ":fromContext", error.getMessage(), error);
105105
return new NoopSpan(INVALID);
106106
}

common4j/src/main/com/microsoft/identity/common/java/opentelemetry/TextMapPropagatorExtension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void set(final Map<String, String> carrier, final String key, final Strin
7272
);
7373
propagator.inject(contextToInject, carrier, setter);
7474
return carrier;
75-
} catch (final Exception e) {
75+
} catch (final Exception | NoSuchMethodError e) {
7676
// Log the error and return an empty map if injection fails
7777
Logger.error(TAG + ":inject", "Failed to inject context", e);
7878
return new HashMap<>();
@@ -109,7 +109,7 @@ public Iterable<String> keys(final Map<String, String> carrier) {
109109
W3CBaggagePropagator.getInstance()
110110
);
111111
return propagator.extract(Context.current(), carrier, getter);
112-
} catch (final Exception e) {
112+
} catch (final Exception | NoSuchMethodError e) {
113113
// Log the error and return null if extraction fails
114114
Logger.error(TAG + ":extract", "Failed to extract context", e);
115115
return null;

0 commit comments

Comments
 (0)