GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Return null or the default from getTimeMillis() for invalid dates by CCCLL · Pull Request #17965 · netty/netty

Conversation

@CCCLL

@CCCLL CCCLL commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Motivation:

Headers.getTimeMillis(name) is documented to return null, and getTimeMillis(name, defaultValue) the default value, when the header value is not a date. CharSequenceValueConverter.convertToTimeMillis(...) reports an unparsable value by throwing a java.text.ParseException through PlatformDependent.throwException(...), although the method does not declare it. DefaultHeaders.getTimeMillis(...) only catches RuntimeException, so the checked exception escapes to the caller, and ReadOnlyHttpHeaders and ReadOnlyHttp2Headers call the converter without catching anything.

For example, a handler that calls request.headers().getTimeMillis(IF_MODIFIED_SINCE, -1) for a request with If-Modified-Since: yesterday gets a ParseException in exceptionCaught(...) instead of -1. DefaultHttpHeaders, DefaultHttp2Headers and the read-only headers all behave like this.

This was fixed on the old Netty 5 branch in #11853 but never made it to 4.x.

Modification:

Port #11853: throw the unchecked DateTimeParseException from convertToTimeMillis(...), and catch RuntimeException in the getTimeMillis(...) methods of ReadOnlyHttpHeaders and ReadOnlyHttp2Headers like DefaultHeaders does. Add tests for values that are not dates.

Result:

getTimeMillis(...) and getTimeMillisAndRemove(...) return null or the default value for a header that is not a date, as documented. Code that calls convertToTimeMillis(...) directly now gets a DateTimeParseException instead of an undeclared ParseException.

HttpServerCodec followed by a handler that calls getTimeMillis(IF_MODIFIED_SINCE, -1), request with If-Modified-Since: yesterday:

Before:

handler: exceptionCaught java.text.ParseException: header can't be parsed into a Date: yesterday
DefaultHttp2Headers.getTimeMillis threw java.text.ParseException: header can't be parsed into a Date: yesterday
ReadOnlyHttpHeaders.getTimeMillis(name, -1) threw java.text.ParseException: header can't be parsed into a Date: yesterday

After:

handler: getTimeMillis(if-modified-since, -1) = -1
DefaultHttp2Headers.getTimeMillis = null
ReadOnlyHttpHeaders.getTimeMillis(name, -1) = -1

The new assertions fail before the change. codec-base, codec-http, codec-http2 and codec-stomp tests pass.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@CCCLL CCCLL mentioned this pull request Oct 21, 2026
Return null or the default from read-only headers for invalid values #17967
Merged
normanmaurer added a commit that referenced this pull request Oct 22, 2026
@CCCLL @normanmaurer
Return null or the default from read-only headers for invalid values (#…
5f89d65
…17967)

Motivation:

`HttpHeaders.getInt(name)` and `getShort(name)`, and the typed getters
of `Headers`, are documented to return `null`, and the overloads with a
default value the default value, when the header value can't be
converted. `DefaultHeaders` catches conversion failures since #7710, but
`ReadOnlyHttpHeaders.getInt(...)` and `getShort(...)`, and
`ReadOnlyHttp2Headers.getByte(...)`, `getChar(...)`, `getShort(...)`,
`getInt(...)`, `getLong(...)`, `getFloat(...)` and `getDouble(...)` let
the `NumberFormatException`, or the `IndexOutOfBoundsException` of
`getChar(...)` for an empty value, escape to the caller.

For example, `HttpToHttp2ConnectionHandler` reads
`x-http2-stream-weight` with `getShort(name, defaultValue)`. A request
with `x-http2-stream-weight: high` is written with the default weight
when it uses `DefaultHttpHeaders`, but with `ReadOnlyHttpHeaders` the
write fails with a `NumberFormatException` and the handler sends GOAWAY.

Modification:

Catch `RuntimeException` around the conversion in these getters, like
`DefaultHeaders` does. `getTimeMillis(...)` is covered by #17965. Add
tests for values that can't be converted.

Result:

The getters of `ReadOnlyHttpHeaders` and `ReadOnlyHttp2Headers` return
`null` or the default value for a value that can't be converted, like
`DefaultHttpHeaders` and `DefaultHttp2Headers`.

Headers `x-count: abc` and `x-empty:` (empty value);
`DefaultHttpHeaders` and `DefaultHttp2Headers` return `null` or `-1` for
all of these. Then a request with `x-http2-stream-weight: high` written
through `HttpToHttp2ConnectionHandler`:

Before:

```
ReadOnlyHttpHeaders.getInt(x-count, -1) threw java.lang.NumberFormatException: For input string: "abc"
ReadOnlyHttpHeaders.getShort(x-count) threw java.lang.NumberFormatException: For input string: "abc"
ReadOnlyHttp2Headers.getChar(x-empty) threw java.lang.IndexOutOfBoundsException: index: 0 must be in the range [0,0)
ReadOnlyHttp2Headers.getLong(x-count) threw java.lang.NumberFormatException: abc
ReadOnlyHttp2Headers.getDouble(x-count, -1) threw java.lang.NumberFormatException: For input string: "abc"
HttpToHttp2ConnectionHandler write with DefaultHttpHeaders: success=true, first outbound frame type=1 (HEADERS)
HttpToHttp2ConnectionHandler write with ReadOnlyHttpHeaders: success=false cause=java.lang.NumberFormatException: For input string: "high", first outbound frame type=7 (GOAWAY)
```

After:

```
ReadOnlyHttpHeaders.getInt(x-count, -1) = -1
ReadOnlyHttpHeaders.getShort(x-count) = null
ReadOnlyHttp2Headers.getChar(x-empty) = null
ReadOnlyHttp2Headers.getLong(x-count) = null
ReadOnlyHttp2Headers.getDouble(x-count, -1) = -1.0
HttpToHttp2ConnectionHandler write with DefaultHttpHeaders: success=true, first outbound frame type=1 (HEADERS)
HttpToHttp2ConnectionHandler write with ReadOnlyHttpHeaders: success=true, first outbound frame type=1 (HEADERS)
```

The new tests fail before the change. `codec-http` and `codec-http2`
tests pass.

---------

Co-authored-by: Norman Maurer <[email protected]>
This was referenced Oct 22, 2026
Auto-port 4.1: Return null or the default from read-only headers for invalid values #18017
Merged
Auto-port 5.0: Return null or the default from read-only headers for invalid values #18021
Merged
@normanmaurer

normanmaurer commented Oct 22, 2026

Copy link
Copy Markdown
Member

@CCCLL please rebase

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

CCCLL added 2 commits October 22, 2026 22:44
@CCCLL
Return null or the default from getTimeMillis() for invalid dates
4b19a85
Motivation:

Headers.getTimeMillis(name) is documented to return null, and
getTimeMillis(name, defaultValue) the default value, when the header
value is not a date. CharSequenceValueConverter.convertToTimeMillis(...)
reports an unparsable value by throwing a java.text.ParseException
through PlatformDependent.throwException(...), although the method does
not declare it. DefaultHeaders.getTimeMillis(...) only catches
RuntimeException, so the checked exception escapes to the caller, and
ReadOnlyHttpHeaders and ReadOnlyHttp2Headers call the converter without
catching anything.

For example, a handler that calls
request.headers().getTimeMillis(IF_MODIFIED_SINCE, -1) for a request
with "If-Modified-Since: yesterday" gets a ParseException in
exceptionCaught(...) instead of -1. DefaultHttpHeaders,
DefaultHttp2Headers and the read-only headers all behave like this.

This was fixed on the old Netty 5 branch in netty#11853 but never made it to
4.x.

Modification:

Port netty#11853: throw the unchecked DateTimeParseException from
convertToTimeMillis(...), and catch RuntimeException in the
getTimeMillis(...) methods of ReadOnlyHttpHeaders and
ReadOnlyHttp2Headers like DefaultHeaders does. Add tests for values that
are not dates.

Result:

getTimeMillis(...) and getTimeMillisAndRemove(...) return null or the
default value for a header that is not a date, as documented. Code that
calls convertToTimeMillis(...) directly now gets a
DateTimeParseException instead of an undeclared ParseException.
@CCCLL
Rename caught RuntimeException to ignore
67503fc
@CCCLL
CCCLL force-pushed the header-time-millis-parse-exception branch from ab6a6fa to 67503fc Compare October 22, 2026 14:48
normanmaurer added a commit that referenced this pull request Oct 22, 2026
@netty-project-bot @CCCLL @normanmaurer
Auto-port 5.0: Return null or the default from read-only headers for …
0aa35c0
…invalid values (#18021)

Auto-port of #17967 to 5.0
Cherry-picked commit: 5f89d65

---
Motivation:

`HttpHeaders.getInt(name)` and `getShort(name)`, and the typed getters
of `Headers`, are documented to return `null`, and the overloads with a
default value the default value, when the header value can't be
converted. `DefaultHeaders` catches conversion failures since #7710, but
`ReadOnlyHttpHeaders.getInt(...)` and `getShort(...)`, and
`ReadOnlyHttp2Headers.getByte(...)`, `getChar(...)`, `getShort(...)`,
`getInt(...)`, `getLong(...)`, `getFloat(...)` and `getDouble(...)` let
the `NumberFormatException`, or the `IndexOutOfBoundsException` of
`getChar(...)` for an empty value, escape to the caller.

For example, `HttpToHttp2ConnectionHandler` reads
`x-http2-stream-weight` with `getShort(name, defaultValue)`. A request
with `x-http2-stream-weight: high` is written with the default weight
when it uses `DefaultHttpHeaders`, but with `ReadOnlyHttpHeaders` the
write fails with a `NumberFormatException` and the handler sends GOAWAY.

Modification:

Catch `RuntimeException` around the conversion in these getters, like
`DefaultHeaders` does. `getTimeMillis(...)` is covered by #17965. Add
tests for values that can't be converted.

Result:

The getters of `ReadOnlyHttpHeaders` and `ReadOnlyHttp2Headers` return
`null` or the default value for a value that can't be converted, like
`DefaultHttpHeaders` and `DefaultHttp2Headers`.

Co-authored-by: CCCLL <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Oct 22, 2026
@netty-project-bot @CCCLL @normanmaurer
Auto-port 4.1: Return null or the default from read-only headers for …
cd755e0
…invalid values (#18017)

Auto-port of #17967 to 4.1
Cherry-picked commit: 5f89d65

---
Motivation:

`HttpHeaders.getInt(name)` and `getShort(name)`, and the typed getters
of `Headers`, are documented to return `null`, and the overloads with a
default value the default value, when the header value can't be
converted. `DefaultHeaders` catches conversion failures since #7710, but
`ReadOnlyHttpHeaders.getInt(...)` and `getShort(...)`, and
`ReadOnlyHttp2Headers.getByte(...)`, `getChar(...)`, `getShort(...)`,
`getInt(...)`, `getLong(...)`, `getFloat(...)` and `getDouble(...)` let
the `NumberFormatException`, or the `IndexOutOfBoundsException` of
`getChar(...)` for an empty value, escape to the caller.

For example, `HttpToHttp2ConnectionHandler` reads
`x-http2-stream-weight` with `getShort(name, defaultValue)`. A request
with `x-http2-stream-weight: high` is written with the default weight
when it uses `DefaultHttpHeaders`, but with `ReadOnlyHttpHeaders` the
write fails with a `NumberFormatException` and the handler sends GOAWAY.

Modification:

Catch `RuntimeException` around the conversion in these getters, like
`DefaultHeaders` does. `getTimeMillis(...)` is covered by #17965. Add
tests for values that can't be converted.

Result:

The getters of `ReadOnlyHttpHeaders` and `ReadOnlyHttp2Headers` return
`null` or the default value for a value that can't be converted, like
`DefaultHttpHeaders` and `DefaultHttp2Headers`.


Co-authored-by: CCCLL <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
@testlens-app

testlens-app Bot commented Oct 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

🚨 TestLens detected 2 failed tests 🚨

Test Summary

Tip

Inspect all details with the TestLens CLI: testlens pr 17965

Build PR / linux-x86_64-java11 build > Netty/Codec/HTTP2

Test Runs Flakiness
Http2MultiplexTransportTest ❌ 1% 🟡

Build PR / windows-x86_64-java11-boringssl > Netty/Codec/HTTP

Test Runs Flakiness
WebSocketHandshakeHandOverTest > testClientHandshakerForceClose() ❌ 1% 🟡

🏷️ Commit: 67503fc
▶️ Tests: 135805 executed
⚪️ Checks: 26/26 completed

Test Failures

Http2MultiplexTransportTest (Netty/Codec/HTTP2 in Build PR / linux-x86_64-java11 build)
java.lang.IllegalStateException: Possible memory leak detected for resource scope 'Http2MultiplexTransportTest'. Please use paranoid leak detection to get more information, or set -Dio.netty.util.LeakPresenceDetector.trackCreationStack=true
	at io.netty.util.LeakPresenceDetector$ResourceScope.check(LeakPresenceDetector.java:308)
	at io.netty.util.LeakPresenceDetector$ResourceScope.close(LeakPresenceDetector.java:328)
	at io.netty.util.test.LeakPresenceExtension.afterAll(LeakPresenceExtension.java:140)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
WebSocketHandshakeHandOverTest > testClientHandshakerForceClose() (Netty/Codec/HTTP in Build PR / windows-x86_64-java11-boringssl)
org.opentest4j.AssertionFailedError: expected: <false> but was: <true>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertFalse.failNotFalse(AssertFalse.java:63)
	at org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:36)
	at org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:31)
	at org.junit.jupiter.api.Assertions.assertFalse(Assertions.java:231)
	at io.netty.handler.codec.http.websocketx.WebSocketHandshakeHandOverTest.testClientHandshakerForceClose(WebSocketHandshakeHandOverTest.java:269)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:396)
	at java.base/java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:721)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
expected actual
false true

Rerun Controls

Select tests to mute in this pull request:

  • Http2MultiplexTransportTest
  • WebSocketHandshakeHandOverTest > testClientHandshakerForceClose()

Reuse successful test results:

  • ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app/docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@netty-project-bot @CCCLL
@normanmaurer @lltopk
Auto-port 4.1: Return null or the default from read-only headers for …
1ad5987
…invalid values (netty#18017)

Auto-port of netty#17967 to 4.1
Cherry-picked commit: 5f89d65

---
Motivation:

`HttpHeaders.getInt(name)` and `getShort(name)`, and the typed getters
of `Headers`, are documented to return `null`, and the overloads with a
default value the default value, when the header value can't be
converted. `DefaultHeaders` catches conversion failures since netty#7710, but
`ReadOnlyHttpHeaders.getInt(...)` and `getShort(...)`, and
`ReadOnlyHttp2Headers.getByte(...)`, `getChar(...)`, `getShort(...)`,
`getInt(...)`, `getLong(...)`, `getFloat(...)` and `getDouble(...)` let
the `NumberFormatException`, or the `IndexOutOfBoundsException` of
`getChar(...)` for an empty value, escape to the caller.

For example, `HttpToHttp2ConnectionHandler` reads
`x-http2-stream-weight` with `getShort(name, defaultValue)`. A request
with `x-http2-stream-weight: high` is written with the default weight
when it uses `DefaultHttpHeaders`, but with `ReadOnlyHttpHeaders` the
write fails with a `NumberFormatException` and the handler sends GOAWAY.

Modification:

Catch `RuntimeException` around the conversion in these getters, like
`DefaultHeaders` does. `getTimeMillis(...)` is covered by netty#17965. Add
tests for values that can't be converted.

Result:

The getters of `ReadOnlyHttpHeaders` and `ReadOnlyHttp2Headers` return
`null` or the default value for a value that can't be converted, like
`DefaultHttpHeaders` and `DefaultHttp2Headers`.


Co-authored-by: CCCLL <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
@CCCLL

CCCLL commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@normanmaurer I rebased this onto 4.2 right after your comment and added a commit that renames the caught exceptions to ignore, as you did in #17967. The two failed jobs hit Http2MultiplexTransportTest and WebSocketHandshakeHandOverTest, which TestLens marks as flaky; the tests this PR changes passed in both jobs. Could you take another look?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@CCCLL @normanmaurer
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.