Skip to content

Fix NumberFormatException in SketchTool.loadSketchesFromString for single-k sketches#22

Open
rec3141 wants to merge 1 commit into
bbushnell:masterfrom
rec3141:fix/sendsketch-single-k-numberformat
Open

Fix NumberFormatException in SketchTool.loadSketchesFromString for single-k sketches#22
rec3141 wants to merge 1 commit into
bbushnell:masterfrom
rec3141:fix/sendsketch-single-k-numberformat

Conversation

@rec3141

@rec3141 rec3141 commented Jun 11, 2026

Copy link
Copy Markdown

Fixes #23.

Summary

TaxServer (the sendsketch.sh server) returns HTTP 400 for every query whose sketch uses a single k-mer length (e.g. a local k=31 sketch server), due to a NumberFormatException in SketchTool.loadSketchesFromString().

Root cause

In current/sketch/SketchTool.java, the K: (k-mer length) header parser in loadSketchesFromString() has a comma branch (dual-k, e.g. K:32,24) and a single-value branch. The single-value branch parsed the full field string s ("K:31") instead of the value substring sub ("31"):

}else if(s.startsWith("K:")){//Kmer length
    if(sub.indexOf(',')>=0){
        String[] subsplit=sub.split(",");
        int x=Integer.parseInt(subsplit[0]);
        int y=Integer.parseInt(subsplit[1]);
        ...
    }else{
        k_sketch=Integer.parseInt(s);   // <-- "K:31" is not an int -> NumberFormatException
        k2_sketch=0;
    }
}

Every other field parser in the same block (H:, BC:, GS:, GK:, …) and the comma branch correctly use sub. Only this single-k branch used s. The two file-reading parsers (loadSketchesFromSketchFile/...File2) were already correct — only loadSketchesFromString (the path that parses incoming sendsketch POST data) was affected.

Fix

-										k_sketch=Integer.parseInt(s);
+										k_sketch=Integer.parseInt(sub);

Reproduction & verification (on current master, v39.91)

Built two tiny per-sequence sketch DBs from a 5-contig FASTA, started TaxServer with each, and queried via sendsketch.sh:

query sketch unpatched 39.91 patched
single k=31 (K:31) HTTP 400 / NumberFormatException ✅ returns results
default dual-k (K:32,24) ✅ returns results ✅ returns results

So default dual-k sketches were never affected (they take the comma branch) — which is why public default-k servers never hit this — but any single-k custom server (common for self-hosted GTDB/RefSeq sketch DBs built with k=31) returns 400 on every query. The fix restores single-k servers while leaving the dual-k path unchanged.

Environment

  • BBTools master @ v39.91 (also confirmed present in 39.52)
  • OpenJDK 11

🤖 Generated with Claude Code — model: Claude Opus 4.8 (1M context) (claude-opus-4-8[1m])

…ngle-k sketches

The single-k (no comma) branch of the K: header parser passed the full
field string `s` (e.g. "K:31") to Integer.parseInt instead of the value
substring `sub` (e.g. "31"), throwing NumberFormatException. This made
TaxServer return HTTP 400 for every sendsketch query whose sketch uses a
single kmer length (e.g. a local k=31 sketch server). The two file-reading
parsers and the comma branch already use `sub` correctly; only this branch
was affected, so default dual-k (k=32,24) sketches were unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sendsketch/TaxServer returns HTTP 400 (NumberFormatException) for single-k sketch servers (e.g. k=31)

1 participant