From 42f2e7f733f48b3bf21d28eb7484af077ddd3c4d Mon Sep 17 00:00:00 2001 From: Eric Gribkoff Date: Tue, 21 Jan 2020 14:38:10 -0800 Subject: [PATCH] core: change catch blocks for Android <19 (#6611) Caught by lint warning during import --- .../AbstractManagedChannelImplBuilder.java | 22 ++++++++++++++----- .../internal/AbstractServerImplBuilder.java | 22 ++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/io/grpc/internal/AbstractManagedChannelImplBuilder.java b/core/src/main/java/io/grpc/internal/AbstractManagedChannelImplBuilder.java index 93883da921..507b5d185f 100644 --- a/core/src/main/java/io/grpc/internal/AbstractManagedChannelImplBuilder.java +++ b/core/src/main/java/io/grpc/internal/AbstractManagedChannelImplBuilder.java @@ -576,8 +576,14 @@ public abstract class AbstractManagedChannelImplBuilder recordStartedRpcs, recordFinishedRpcs, recordRealTimeMetrics); - } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException - | InvocationTargetException e) { + } catch (ClassNotFoundException e) { + // Replace these separate catch statements with multicatch when Android min-API >= 19 + log.log(Level.FINE, "Unable to apply census stats", e); + } catch (NoSuchMethodException e) { + log.log(Level.FINE, "Unable to apply census stats", e); + } catch (IllegalAccessException e) { + log.log(Level.FINE, "Unable to apply census stats", e); + } catch (InvocationTargetException e) { log.log(Level.FINE, "Unable to apply census stats", e); } if (statsInterceptor != null) { @@ -595,9 +601,15 @@ public abstract class AbstractManagedChannelImplBuilder Method getClientInterceptroMethod = censusTracingAccessor.getDeclaredMethod("getClientInterceptor"); tracingInterceptor = (ClientInterceptor) getClientInterceptroMethod.invoke(null); - } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException - | InvocationTargetException e) { - log.log(Level.FINE, "Unable to apply census tracing", e); + } catch (ClassNotFoundException e) { + // Replace these separate catch statements with multicatch when Android min-API >= 19 + log.log(Level.FINE, "Unable to apply census stats", e); + } catch (NoSuchMethodException e) { + log.log(Level.FINE, "Unable to apply census stats", e); + } catch (IllegalAccessException e) { + log.log(Level.FINE, "Unable to apply census stats", e); + } catch (InvocationTargetException e) { + log.log(Level.FINE, "Unable to apply census stats", e); } if (tracingInterceptor != null) { effectiveInterceptors.add(0, tracingInterceptor); diff --git a/core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java b/core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java index ff151d1a6d..6928434df3 100644 --- a/core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java +++ b/core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java @@ -253,8 +253,14 @@ public abstract class AbstractServerImplBuilder= 19 + log.log(Level.FINE, "Unable to apply census stats", e); + } catch (NoSuchMethodException e) { + log.log(Level.FINE, "Unable to apply census stats", e); + } catch (IllegalAccessException e) { + log.log(Level.FINE, "Unable to apply census stats", e); + } catch (InvocationTargetException e) { log.log(Level.FINE, "Unable to apply census stats", e); } if (censusStatsTracerFactory != null) { @@ -270,9 +276,15 @@ public abstract class AbstractServerImplBuilder= 19 + log.log(Level.FINE, "Unable to apply census stats", e); + } catch (NoSuchMethodException e) { + log.log(Level.FINE, "Unable to apply census stats", e); + } catch (IllegalAccessException e) { + log.log(Level.FINE, "Unable to apply census stats", e); + } catch (InvocationTargetException e) { + log.log(Level.FINE, "Unable to apply census stats", e); } if (tracingStreamTracerFactory != null) { tracerFactories.add(tracingStreamTracerFactory);