Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import edu.berkeley.cs.jqf.fuzz.random.NoGuidance;
import io.opentelemetry.api.internal.PercentEscaper;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
import org.junit.runner.Result;
import org.junit.runner.RunWith;
Expand All @@ -22,10 +23,11 @@ class PercentEscaperFuzzTest {
public static class TestCases {
private final PercentEscaper percentEscaper = new PercentEscaper();

@SuppressWarnings("JdkObsolete") // Recommended alternative was introduced in java 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oddly, errorprone makes the mistake of flagging URLDecoder.decode(String, String) as obsolete recommending using URLDecoder.decode(String, Charset) only available in java 10. Seems like being language-version-aware would have to be a key consideration of this type of obsolete API detection.

Maybe its just a mistake?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we hit this in contrib too: open-telemetry/opentelemetry-java-contrib#2617

@Fuzz
public void roundTripWithUrlDecoder(String value) throws Exception {
String escaped = percentEscaper.escape(value);
String decoded = URLDecoder.decode(escaped, "UTF-8");
String decoded = URLDecoder.decode(escaped, StandardCharsets.UTF_8.name());
assertThat(decoded).isEqualTo(value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rootProject.extra["versions"] = dependencyVersions


val autoValueVersion = "1.11.1"
val errorProneVersion = "2.46.0"
val errorProneVersion = "2.47.0"
val jmhVersion = "1.37"
// Mockito 5.x.x requires Java 11 https://github.com/mockito/mockito/releases/tag/v5.0.0
val mockitoVersion = "4.11.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ protected abstract T createExporter(

protected abstract T createDefaultExporter();

@SuppressWarnings("JdkObsolete") // Recommended alternative was introduced in java 10
private String output(@Nullable OutputStream outputStream, @Nullable Path file) {
if (outputStream == null) {
return logs.getEvents().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public static void configureOtlpExporterBuilder(
ExporterBuilderUtil.configureExporterMemoryMode(config, setMemoryMode);
}

@SuppressWarnings("JdkObsolete") // Recommended alternative was introduced in java 10
static void configureOtlpHeaders(
ConfigProperties config, String dataType, BiConsumer<String, String> addHeader) {
Map<String, String> headers = config.getMap("otel.exporter.otlp." + dataType + ".headers");
Expand All @@ -162,7 +163,7 @@ static void configureOtlpHeaders(
try {
// headers are encoded as URL - see
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specifying-headers-via-environment-variables
addHeader.accept(key, URLDecoder.decode(value, StandardCharsets.UTF_8.displayName()));
addHeader.accept(key, URLDecoder.decode(value, StandardCharsets.UTF_8.name()));
} catch (Exception e) {
throw new ConfigurationException("Cannot decode header value: " + value, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ private static String toPattern(String expected) {
return regexBuilder.toString();
}

@SuppressWarnings("JdkObsolete") // Recommended alternative was introduced in java 10
private static String toOpenMetrics(MetricSnapshots snapshots) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
OpenMetricsTextFormatWriter writer = new OpenMetricsTextFormatWriter(true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.opentelemetry.context.propagation.TextMapSetter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.logging.Level;
Expand Down Expand Up @@ -156,6 +157,7 @@ public String toString() {
return "JaegerPropagator";
}

@SuppressWarnings("JdkObsolete") // Recommended alternative was introduced in java 10
private static <C> SpanContext getSpanContextFromHeader(
@Nullable C carrier, TextMapGetter<C> getter) {
String value = getter.get(carrier, PROPAGATION_HEADER);
Expand All @@ -168,7 +170,7 @@ private static <C> SpanContext getSpanContextFromHeader(
if (value.lastIndexOf(PROPAGATION_HEADER_DELIMITER) == -1) {
try {
// the propagation value
value = URLDecoder.decode(value, "UTF-8");
value = URLDecoder.decode(value, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
logger.fine(
"Error decoding '"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.opentelemetry.context.propagation.TextMapSetter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -357,13 +358,15 @@ void extract_SampledContext_Short_TraceId() {
}

@Test
@SuppressWarnings("JdkObsolete") // Recommended alternative was introduced in java 10
void extract_UrlEncodedContext() throws UnsupportedEncodingException {
Map<String, String> carrier = new LinkedHashMap<>();
JaegerSpanContext context =
new JaegerSpanContext(
TRACE_ID_HI, TRACE_ID_LOW, SPAN_ID_LONG, DEPRECATED_PARENT_SPAN_LONG, (byte) 5);
carrier.put(
PROPAGATION_HEADER, URLEncoder.encode(TextMapCodec.contextAsString(context), "UTF-8"));
PROPAGATION_HEADER,
URLEncoder.encode(TextMapCodec.contextAsString(context), StandardCharsets.UTF_8.name()));

assertThat(getSpanContext(jaegerPropagator.extract(Context.current(), carrier, getter)))
.isEqualTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static Resource createEnvironmentResource() {
* @param config the {@link ConfigProperties} used to obtain resource properties
* @return the resource.
*/
@SuppressWarnings("JdkObsolete") // Recommended alternative was introduced in java 10
public static Resource createEnvironmentResource(ConfigProperties config) {
AttributesBuilder resourceAttributes = Attributes.builder();
try {
Expand All @@ -74,7 +75,7 @@ public static Resource createEnvironmentResource(ConfigProperties config) {
// Attributes specified via otel.resource.attributes follow the W3C Baggage spec and
// characters outside the baggage-octet range are percent encoded
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable
URLDecoder.decode(entry.getValue(), StandardCharsets.UTF_8.displayName()));
URLDecoder.decode(entry.getValue(), StandardCharsets.UTF_8.name()));
}
} catch (UnsupportedEncodingException e) {
// Should not happen since always using standard charset
Expand Down
Loading