eclipse-ee4j / eclipse-ee4j/jersey

SSE: IllegalFormatConversionException when creating EventSource

Open
#3,479 4 comments 0 reactions 0 assignees View on GitHub
Client Component: media Priority: Major sse Type: Bug
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

When creating an EventSource from a WebTarget with a URI containing a percent sign (f.i. a query parameter with a colon, which is URL encoded into "%3A"), an IllegalFormatConversionException is thrown, because the name of the Thread is built with String.format, but including the URI in the format argument.

```
**Example Code**WebTarget target = client.target(someUriString).path(somePathComponent).queryParam("this-causes-percents-chars-in-the-URI", "a:b");

// this eventually calls String.format, which tries to replace the percent character and fails EventSource eventSource = EventSource.target(target).build();
```
```
**Stacktrace** java.util.IllegalFormatConversionException: a != java.lang.Integer
at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302)
at java.util.Formatter$FormatSpecifier.printFloat(Formatter.java:2806)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2753)
at java.util.Formatter.format(Formatter.java:2520)
at java.util.Formatter.format(Formatter.java:2455)
at java.lang.String.format(String.java:2940)
at jersey.repackaged.com.google.common.util.concurrent.ThreadFactoryBuilder.setNameFormat(ThreadFactoryBuilder.java:71)
at org.glassfish.jersey.media.sse.EventSource.(EventSource.java:387)
at org.glassfish.jersey.media.sse.EventSource.(EventSource.java:134)
at org.glassfish.jersey.media.sse.EventSource$Builder.build(EventSource.java:278)
```

The problem is the following line

```
new ThreadFactoryBuilder().setNameFormat(esName + "-%d")
```

where esName contains the URI with the % sign.
#### Affected Versions
[2.22.2, 2.25]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.