|
10 | 10 | import io.opentelemetry.api.common.KeyValue; |
11 | 11 | import io.opentelemetry.api.common.Value; |
12 | 12 | import io.opentelemetry.common.impl.ApiUsageLogger; |
| 13 | +import io.opentelemetry.context.Context; |
13 | 14 | import io.opentelemetry.context.propagation.ContextPropagators; |
14 | 15 | import io.opentelemetry.internal.testing.slf4j.SuppressLogger; |
15 | 16 | import java.io.File; |
|
43 | 44 | import java.util.Map; |
44 | 45 | import java.util.Objects; |
45 | 46 | import java.util.Set; |
| 47 | +import java.util.concurrent.Callable; |
| 48 | +import java.util.concurrent.Executor; |
| 49 | +import java.util.concurrent.ExecutorService; |
| 50 | +import java.util.concurrent.ScheduledExecutorService; |
| 51 | +import java.util.function.BiConsumer; |
| 52 | +import java.util.function.BiFunction; |
46 | 53 | import java.util.function.Consumer; |
| 54 | +import java.util.function.Function; |
47 | 55 | import java.util.function.Predicate; |
48 | 56 | import java.util.function.Supplier; |
49 | 57 | import java.util.jar.JarEntry; |
@@ -111,24 +119,81 @@ class NullGuardsTest { |
111 | 119 | * fallbacks in runtime-defaulted artifacts. |
112 | 120 | */ |
113 | 121 | private static final Map<String, GuardStyle> METHOD_STYLE_OVERRIDES = |
114 | | - Map.of( |
115 | | - overrideKey(GlobalOpenTelemetry.class, "set", void.class, OpenTelemetry.class), |
116 | | - GuardStyle.FAIL_FAST, |
117 | | - overrideKey(GlobalOpenTelemetry.class, "set", void.class, Supplier.class), |
118 | | - GuardStyle.FAIL_FAST, |
119 | | - overrideKey( |
| 122 | + Map.ofEntries( |
| 123 | + Map.entry( |
| 124 | + overrideKey(GlobalOpenTelemetry.class, "set", void.class, OpenTelemetry.class), |
| 125 | + GuardStyle.FAIL_FAST), |
| 126 | + Map.entry( |
| 127 | + overrideKey(GlobalOpenTelemetry.class, "set", void.class, Supplier.class), |
| 128 | + GuardStyle.FAIL_FAST), |
| 129 | + Map.entry( |
| 130 | + overrideKey( |
120 | 131 | OpenTelemetry.class, |
121 | 132 | "propagating", |
122 | 133 | OpenTelemetry.class, |
123 | 134 | ContextPropagators.class), |
124 | | - GuardStyle.FAIL_FAST, |
| 135 | + GuardStyle.FAIL_FAST), |
| 136 | + // Context wrappers are setup-time adapters. Fail fast rather than defer an NPE until use |
| 137 | + // or substitute a noop that could discard application work or return an invalid result. |
| 138 | + Map.entry( |
| 139 | + overrideKey(Context.class, "taskWrapping", Executor.class, Executor.class), |
| 140 | + GuardStyle.FAIL_FAST), |
| 141 | + Map.entry( |
| 142 | + overrideKey( |
| 143 | + Context.class, "taskWrapping", ExecutorService.class, ExecutorService.class), |
| 144 | + GuardStyle.FAIL_FAST), |
| 145 | + Map.entry( |
| 146 | + overrideKey( |
| 147 | + Context.class, |
| 148 | + "taskWrapping", |
| 149 | + ScheduledExecutorService.class, |
| 150 | + ScheduledExecutorService.class), |
| 151 | + GuardStyle.FAIL_FAST), |
| 152 | + Map.entry( |
| 153 | + overrideKey(Context.class, "wrap", Executor.class, Executor.class), |
| 154 | + GuardStyle.FAIL_FAST), |
| 155 | + Map.entry( |
| 156 | + overrideKey(Context.class, "wrap", ExecutorService.class, ExecutorService.class), |
| 157 | + GuardStyle.FAIL_FAST), |
| 158 | + Map.entry( |
| 159 | + overrideKey( |
| 160 | + Context.class, |
| 161 | + "wrap", |
| 162 | + ScheduledExecutorService.class, |
| 163 | + ScheduledExecutorService.class), |
| 164 | + GuardStyle.FAIL_FAST), |
| 165 | + Map.entry( |
| 166 | + overrideKey(Context.class, "wrap", Runnable.class, Runnable.class), |
| 167 | + GuardStyle.FAIL_FAST), |
| 168 | + Map.entry( |
| 169 | + overrideKey(Context.class, "wrap", Callable.class, Callable.class), |
| 170 | + GuardStyle.FAIL_FAST), |
| 171 | + Map.entry( |
| 172 | + overrideKey(Context.class, "wrapFunction", Function.class, Function.class), |
| 173 | + GuardStyle.FAIL_FAST), |
| 174 | + Map.entry( |
| 175 | + overrideKey(Context.class, "wrapFunction", BiFunction.class, BiFunction.class), |
| 176 | + GuardStyle.FAIL_FAST), |
| 177 | + Map.entry( |
| 178 | + overrideKey(Context.class, "wrapConsumer", Consumer.class, Consumer.class), |
| 179 | + GuardStyle.FAIL_FAST), |
| 180 | + Map.entry( |
| 181 | + overrideKey(Context.class, "wrapConsumer", BiConsumer.class, BiConsumer.class), |
| 182 | + GuardStyle.FAIL_FAST), |
| 183 | + Map.entry( |
| 184 | + overrideKey(Context.class, "wrapSupplier", Supplier.class, Supplier.class), |
| 185 | + GuardStyle.FAIL_FAST), |
125 | 186 | // Value.empty() cannot preserve these generic return types. We may reevaluate in future. |
126 | | - overrideKey(Value.class, "of", Value.class, String.class), GuardStyle.FAIL_FAST, |
127 | | - overrideKey(Value.class, "of", Value.class, byte[].class), GuardStyle.FAIL_FAST, |
128 | | - overrideKey(Value.class, "of", Value.class, Value[].class), GuardStyle.FAIL_FAST, |
129 | | - overrideKey(Value.class, "of", Value.class, List.class), GuardStyle.FAIL_FAST, |
130 | | - overrideKey(Value.class, "of", Value.class, KeyValue[].class), GuardStyle.FAIL_FAST, |
131 | | - overrideKey(Value.class, "of", Value.class, Map.class), GuardStyle.FAIL_FAST); |
| 187 | + Map.entry( |
| 188 | + overrideKey(Value.class, "of", Value.class, String.class), GuardStyle.FAIL_FAST), |
| 189 | + Map.entry( |
| 190 | + overrideKey(Value.class, "of", Value.class, byte[].class), GuardStyle.FAIL_FAST), |
| 191 | + Map.entry( |
| 192 | + overrideKey(Value.class, "of", Value.class, Value[].class), GuardStyle.FAIL_FAST), |
| 193 | + Map.entry(overrideKey(Value.class, "of", Value.class, List.class), GuardStyle.FAIL_FAST), |
| 194 | + Map.entry( |
| 195 | + overrideKey(Value.class, "of", Value.class, KeyValue[].class), GuardStyle.FAIL_FAST), |
| 196 | + Map.entry(overrideKey(Value.class, "of", Value.class, Map.class), GuardStyle.FAIL_FAST)); |
132 | 197 |
|
133 | 198 | private static String overrideKey( |
134 | 199 | Class<?> owner, String name, Class<?> returnType, Class<?>... paramTypes) { |
|
0 commit comments