Package dev.relism.flash.http2
Class Http2Exception
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
dev.relism.flash.http2.Http2Exception
- All Implemented Interfaces:
Serializable
A connection-level HTTP/2 error. Thrown anywhere a peer's frame, HPACK block, or
SETTINGS value violates the protocol in a way that leaves the connection's state (the HPACK
dynamic table, a flow-control window, the stream table) unrecoverable.
single site: it sends
GOAWAY with errorCode() and closes the connection.
Compare Http2StreamException, whose scope is one stream and which results in
RST_STREAM while the connection survives.
Deliberately does not extend IOException: the connection loop
distinguishes a protocol violation (a decision Flash made about the peer's bytes) from a
socket failure (the peer went away) by catching these as unrelated types. Conflating them
would make it possible to accidentally treat a hostile peer's malformed frame as a harmless
disconnect, or vice versa.
Why stack traces are disabled
This exception is thrown on the connection's hot rejection path — a single malformed byte from a hostile or buggy peer can trigger it, and under a scripted attack that can happen many times per second across many connections. JVM stack trace capture (fillInStackTrace)
is by far the most expensive part of constructing a Throwable, and it buys nothing
here: the call site is exactly where errorCode() says it is, and the debug message
already names the specific violation. The 4-argument RuntimeException constructor
disables both suppression and stack-trace writing.
Preallocated singletons
For the common, message-less rejections (frame validation failures, HPACK structural errors) this class exposes shared singleton instances. Reusing one instance across threads and across many throws is safe only because the instance carries no per-throw mutable state and writable-stack-trace is disabled — nothing about a throw mutates the exception object.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Http2Exceptionstatic final Http2Exceptionstatic final Http2Exceptionstatic final Http2Exceptionstatic final Http2Exceptionstatic final Http2Exception -
Method Summary
Modifier and TypeMethodDescriptionThe RFC 9113 §7 error code to send in theGOAWAYframe.static Http2Exceptionof(Http2ErrorCode code, String message) Builds a connection error carrying a caller-supplied debug message.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
PROTOCOL_ERROR
-
FRAME_SIZE_ERROR
-
FLOW_CONTROL_ERROR
-
COMPRESSION_ERROR
-
INTERNAL_ERROR
-
SETTINGS_TIMEOUT
-
-
Method Details
-
errorCode
The RFC 9113 §7 error code to send in theGOAWAYframe. -
of
Builds a connection error carrying a caller-supplied debug message. Allocates a new message carries information specific to this occurrence (e.g. the offending stream id or a decoded value); use one of the preallocated singletons below when it does not.
-