x402's Java SDK rejects the payload the spec tells clients to send
The x402 monorepo carries a Java module of 949 lines. It is not in the reference SDK list, it has no end-to-end coverage, and it is not on Maven Central. We built it and pointed it at real code. The servlet filter rejects the payload the spec tells clients to send.
This post is a defect census, not a roadmap. Every claim below was reproduced on a clean clone of x402-foundation/x402 at commit e2339d7 (2026-11-20), with JDK 17.0.21.1 and Maven 3.9.9. Where a defect needs a reference implementation to matter, we ran the same bytes through @x402/evm 2.31.0 and through the public PayAI facilitator.
What the module is, and what it is not
The java/ directory appeared in June 2025 as a single commit. Nine commits have touched it in total, four of them in 2026: a repo-reference refactor in April, the raw-URI normalization fix and a README version fix in May, and the response-buffering fix in September. The module has 18 main source files and 6 test files, 949 and 1,221 lines respectively.
The repository README lists three reference SDKs: TypeScript, Python and Go. Java is not one of them. Its own README says "you need to build and install it locally" and points at mvn clean install. A search of Maven Central for the group org.x402 returns zero artifacts, and repo1.maven.org/maven2/org/x402/ returns 404. There is no java/ job in the end-to-end suite, which exercises TypeScript, Python and Go clients, servers and facilitators.
None of that is a bug. It is context, and it explains the rest. A module outside the reference list, outside the e2e matrix and outside any package registry accumulates exactly the class of defect that cross-SDK parity work exists to prevent. The two halves of this module map onto the two stacks we have already audited separately: the buyer stack and the seller stack. Java ships one file of each, and neither agrees with the other SDKs.
Defect 1: a spec-conformant payment is rejected before verification
The filter reads the X-PAYMENT header, decodes it, and then performs a local sanity check before calling the facilitator:
payload = PaymentPayload.fromHeader(header);
// simple sanity: resource must match the URL path
if (!Objects.equals(payload.payload.get("resource"), path)) {
respond402(response, path, "resource mismatch");
return;
}
The v1 exact payload that scheme_exact_evm.md defines has two fields inside payload: signature and authorization. The spec's own example carries no resource key. The resource lives in PaymentRequirements, not in the payload.
So payload.payload.get("resource") is null, Objects.equals(null, "/private") is false, and the answer is 402 with "resource mismatch". The facilitator is never called. We fed the spec's example payload, with a matching nonce and payTo, through an embedded Jetty instance with a real filter:
402 | body={"x402Version":1,"accepts":[...],"error":"resource mismatch"}
facilitator.verify calls: 0
The only payload that passes the check is the one org.x402.client.X402HttpClient produces, because that client puts resource inside the payload map itself. The filter and the client are consistent with each other and with nothing else. A payer running @x402/fetch, the Python client, the Go client, or any wallet following the spec gets a 402 it cannot fix by paying.
Defect 2: the client's payload shape is not a payment
That self-consistent shape is worth looking at separately, because it is not a valid payment either. X402HttpClient.get() builds this map:
pl.put("amount", amount.toString());
pl.put("asset", assetContract);
pl.put("payTo", payTo);
pl.put("resource", uri.getPath());
pl.put("nonce", UUID.randomUUID().toString());
pl.put("signature", signer.sign(pl));
There is no authorization object. There is no EIP-712 domain, no validAfter, no validBefore. The nonce is a random UUID rather than the 32-byte hex value EIP-3009 requires. We handed the exact payload this method produces to the published v1 EVM scheme with spec-correct requirements:
{"isValid":false,
"invalidReason":"invalid_exact_evm_payload",
"invalidMessage":"authorization must be an object"}
The client cannot produce a payload the reference facilitator accepts, and the server cannot accept a payload the reference client produces. Both halves of the module agree with each other.
Defect 3: the facilitator request body uses a field nobody else sends
HttpFacilitatorClient.verify() and settle() both build their body with the same three keys:
Map<String,Object> body = Map.of(
"x402Version", 1,
"paymentHeader", paymentHeader,
"paymentRequirements", req
);
The v1 specification's POST /verify section defines paymentPayload as a JSON object, and every other implementation sends that. The Go facilitator client sends paymentPayload. The Python VerifyRequest model declares payment_payload as a required object. The TypeScript client sends paymentPayload. The reference facilitator example destructures { paymentPayload, paymentRequirements } and answers 400 when either is missing.
We captured what the Java resource server actually posts to a facilitator by pointing HttpFacilitatorClient at a JDK HttpServer that logs request bodies:
CAPTURED VERIFY {"paymentRequirements":{...},"paymentHeader":"eyJ4NDAy...","x402Version":1}
Then we sent the same body to the reference facilitator route:
{"error":"Missing paymentPayload or paymentRequirements"}
Against the live PayAI facilitator, which supports v1 exact on base-sepolia, a body carrying only paymentHeader returns:
400 {"isValid":false,"invalidReason":"invalid_payload",
"invalidMessage":": Invalid input: expected object, received undefined"}
The same body with paymentPayload substituted gets past parsing and reaches the actual scheme check. This is not a formatting preference. The Java resource server cannot talk to any facilitator except one written to match it, and no such facilitator is published.
Defect 4: the settlement receipt decodes to blanks
SettlementResponse declares four fields: success, error, txHash and networkId. The v1 specification's settlement response schema names them success, errorReason, transaction, network and payer. The v2 schema is the same shape.
Jackson is configured with FAIL_ON_UNKNOWN_PROPERTIES disabled, so the mismatched keys are not an error; they are silently dropped. We ran a full request through the filter with a facilitator stub returning a spec-shaped body:
{"success":true,"transaction":"0x1234...","network":"eip155:84532","payer":"0x857b..."}
The filter settled successfully, added X-PAYMENT-RESPONSE, and delivered this base64 payload to the buyer:
{"success":true,"transaction":"","network":"","payer":null}
The payment settled. The receipt says nothing about where, or under which transaction hash, or from whom. A buyer that reconciles against the receipt has no transaction to reconcile against, and gets no error telling it so.
Defect 5: a malformed header is a 500 with an unparseable body
Only IllegalArgumentException from base64 decoding maps to a 402. Everything else falls through. A valid base64 encoding of something Jackson cannot map to PaymentPayload throws JsonProcessingException, which extends IOException, which lands in the facilitator-failure branch. A base64 encoding of {} yields a payload with a null map, and the resource check throws NullPointerException, which lands in the generic catch.
Six payloads, six different client mistakes, measured against a real filter:
{} -> 500
null -> 500
xyz -> 500
[] -> 500
{"payload":"x"} -> 500
!!!not-base64!!! -> 402 (the only one classified correctly)
The 500 body is built by concatenation: "{\"error\":\"Payment verification failed: " + ex.getMessage() + "\"}". Jackson's messages contain newlines and unescaped quotes. We captured the response body for xyz and tried to parse it:
status 500, 253 bytes
parses as JSON: NO -> JsonParseException
Illegal unquoted character ((CTRL-CHAR, code 10))
Two consequences. A malformed client header now increments the server's 5xx error rate, which is the metric operators alert on for outages rather than for client garbage. And the error body cannot be machine-read, so a buyer cannot distinguish "your header was malformed" from "the facilitator is down" without string-matching a partially escaped message.
Defect 6: eight replays, eight handler executions, one settlement
The filter has no replay cache and no in-flight marker. Its own comment documents the ordering it relies on: the handler runs inside a buffered response wrapper, and the body is only flushed after facilitator.settle() returns success. That buffering is the same design the TypeScript middleware uses, and the same one whose failure modes showed up in the Go Gin adapter: the buffer is only as good as the path that flushes it. It does not protect the handler's side effects from concurrency.
We built a facilitator stub with a single-use nonce set, the same guarantee a real EIP-3009 token gives, and a handler that increments a counter, which stands in for any non-idempotent action. Then we sent eight concurrent POSTs carrying one identical X-PAYMENT header:
8 concurrent POSTs, one authorization, single-use nonce
HTTP status histogram: {200=1, 402=7}
handler side effects executed: 8
All eight requests passed verification, because all eight verified before any of them settled. All eight executed the handler. Seven then failed settlement and had their bodies discarded. The buyer sees one 200 and seven 402s, which looks correct. The side effects happened eight times. Sequentially the same header also settles twice: two requests, two settlements, then the nonce is spent.
If the handler charges a card, sends a message, or writes a row, it has now done so eight times for one payment. Comparison: the Go adapters have a settlement failure path and the TypeScript resource server has the same buffer-then-settle ordering, but both sit inside an ecosystem where a per-request idempotency discussion is live (issue #4198 has 27 comments on exactly this window). The Java filter is downstream of that discussion and has none of it.
Defect 7: the documented price-table keying makes a route free
The PaymentFilter constructor javadoc is explicit about matching:
Exact, case-sensitive compare of HttpServletRequest#getRequestURI(). Query string included; HTTP method ignored.
getRequestURI() never carries a query string. It is the path plus, at most, matrix parameters. So a price table key written the way the javadoc says to write it — "/report?tenant=a" — can never match, and the route is free:
GET /report?tenant=a with priceTable key "/report?tenant=a"
-> 200 {"data":"PREMIUM"}
This is not an exploitable bypass against a correctly keyed table: the normalization code is careful, and we confirmed that /%70rivate, /private;x and /./private all resolve to the priced route and get a 402, while /private/ and /PRIVATE 404 at the container before the filter sees them. The defect is in the contract: an operator following the documentation ships an unprotected endpoint and has no signal that the protection is off.
Defect 8: the coverage gate that the README advertises does not pass
The badge says 90% and the README says mvn -P coverage verify "Enforces 90% coverage". The profile enforces two limits: instruction coverage 0.85 and branch coverage 0.75. Running it as documented:
[WARNING] Rule violated for bundle x402: branches covered ratio is 0.71,
but expected minimum is 0.75
[INFO] BUILD FAILURE
Exact figures from the JaCoCo CSV: instruction 86.262% (810/939), branch 71.875% (46/64). Line coverage is 83.8% (217/259). The gate the README points at as a quality signal fails on the current commit, and the badge claims a number that is not the configured threshold and is not achieved.
The per-class spread is where the untested branches are: BufferingHttpServletResponseWrapper at 61% line coverage, BufferedServletOutputStream at 56%, Kind at 50%, CryptoSignException at 0%. Those are exactly the classes the concurrency and error-classification defects live in.
What the two open bug reports add
On 2026-11-19, issue #4344 reported defect 1 and issue #4345 reported defect 5, both filed by the same author with a reproduction and a fix in PR #4346 (2 files, +124/−25, open, no reviews). The PR's proposed fix for the resource check is the right shape: reject only when resource is present and differs, otherwise defer to the facilitator.
The PR does not touch defects 2, 3, 4, 6, 7 or 8. Neither does PR #4129 (open since 2026-11-04, 234 files, +27,819/−475) or PR #3820 (open since 2026-10-15, 688 files, +101,012/−529), the two competing v2 rewrites. Both move the current filter to java/legacy/ unchanged, so every defect above carries over to the legacy path by construction. The v2 code in #4129 does use FacilitatorRequest.paymentPayload() and a real HttpFacilitatorClient with bounded bodies, so the body-shape defect is fixed in the new path. The replay window is not: InMemoryPendingSettlementStore exists as a name in the same diff, and whether it closes the concurrent-verify window is a separate question this post does not answer.
What it means for LLM4Agents
Three practical consequences, in order of how much they cost us.
First, the Java path is not a fallback. A large share of enterprise agent code is JVM: Spring Boot services, Quarkus functions, Kafka consumers, and the orchestration layers around them. Our gateway speaks OpenAI-compatible HTTP and settles x402, so a JVM agent that wants to pay per call has two honest options today: call the gateway over plain HTTP and let the gateway hold the wallet, or implement the payment header itself. What it must not do is adopt org.x402:java believing it is a reference SDK. The module is not published, not in the reference list, and rejects the documented payload.
Second, the defects pattern is the warning, not any single defect. A payment stack fails in one of two ways: it rejects a valid payment, or it accepts an invalid one twice. Defects 1 through 4 are the first kind, and they are loud — the buyer sees a 402 and complains. Defects 5 through 7 are the second kind, and they are quiet: a 500 that looks like an outage, a receipt that says nothing, a handler that ran eight times, a route that is free because of a documentation line. A JVM integration that only smoke-tests the happy path will pass and then lose money on the second replay.
Third, the settlement receipt is the audit trail. Defect 4 is the one that hurts most at fleet scale, because it is silent on success. If our gateway ever proxies an x402 settlement through a Java resource server, the receipt it returns must carry the transaction hash and the network, or reconciliation degrades to guessing. Any JVM adapter we ship should validate the receipt it reads rather than trusting a struct that compiles.
scheme_exact_evm.md and confirm the facilitator is called, capture the outbound /verify body and confirm it carries paymentPayload, and settle once with a spec-shaped response and confirm X-PAYMENT-RESPONSE decodes to a non-empty transaction.
Staying on the frontier
Four steps, ordered by cost of delay.
1. Publish the conformance probes as a shared harness. The three checks in the callout are scripts, not opinions. Next step for our stack: add them to the gateway's CI as a vendor-adapter suite, so any JVM SDK we consider is measured on spec payload acceptance, facilitator request shape and receipt decoding before it reaches a paid route. The probes are cheap; the failure they catch is a billing incident.
2. Treat replay as a server-side invariant, not an SDK feature. Defect 6 exists because the filter's contract puts the window between verify and settle and leaves it unclaimed. The same window is the subject of open issue #4198 across the ecosystem. Our gateway already serializes settlement per authorization; the reusable piece is the pattern, and it should be documented as a requirement for any resource server we integrate, in any language. A handler that runs twice for one payment is a bug in the integration, whatever the SDK does.
3. Ship a JVM integration that is explicit about its boundaries. The honest JVM story today is HTTP to the gateway, wallet on the gateway side, no client-side signing. That is also the path with the fewest moving parts and the least exposure to receipt-shape mismatches. If we ever need client-side x402 from the JVM, the starting point is the v2 Java code in #4129 — which fixes the body shape — not the module on main. Track that PR's merge and its pending-settlement store before committing.
4. Keep the coverage gate honest in our own repos. Defect 8 is the cheapest lesson in the post. A badge that advertises 90% while the configured gate fails at 71.875% branches is worse than no badge, because it converts a quality signal into noise. Our own adapters should publish the number the build actually enforces, and the untested classes should be the ones that hold the concurrency and error paths.
The general lesson
x402's strength is that the payment is a signature over an object with a documented schema. That strength collapses the moment a resource server decides it knows better and reads its own field before asking the facilitator. The Java filter does exactly that, in five lines of a null check against a key the spec never defines, and the result is a module that agrees with its own client and with nothing else in the ecosystem.
Cross-SDK parity work is usually framed as keeping error strings identical, which is what we measured across the TypeScript, Go and Python facilitators in the invalidReason census. This module shows the more expensive version: keeping the request shape, the payload shape and the receipt shape identical. An SDK that is 949 lines long, self-consistent, 83.8% line-covered, and wrong about all three is not a smaller version of the reference SDKs. It is a separate protocol.
The bug reports that landed on 2026-11-19 are a good sign: someone read the spec's payload example, ran it, and wrote down what happened. That is the check that was missing, and it is the one worth institutionalizing.
Pay per call, from any runtime
Register an agent, deposit stablecoins, and call 345+ models over an OpenAI-compatible endpoint. Your JVM service needs one HTTP client, not a payment stack.
Register agent