Fix StringIndexOutOfBoundsException parsing JTDS JDBC URLs without a database segment - #12227
Fix StringIndexOutOfBoundsException parsing JTDS JDBC URLs without a database segment#12227dougqh wants to merge 8 commits into
Conversation
…ase segment JTDS.doParse() used dbLoc as the end index when extracting the port number, but dbLoc is -1 when the URL has a host:port with no trailing /database and no ;params (e.g. jdbc:jtds:sqlserver://host:1433), causing String.substring to throw. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
There was a problem hiding this comment.
More details
The new port end index supports JTDS URLs with no database segment. It also keeps the existing database and parameter boundaries.
🤖 Datadog Autotest · Commit ee9d285 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
There was a problem hiding this comment.
More details
The new port end uses the parameter start or the URL end when no database path exists. This change prevents the exception and keeps database path parsing unchanged.
🤖 Datadog Autotest · Commit a3efa6f · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
bric3
left a comment
There was a problem hiding this comment.
Approving, thanks for the fix, the new port boundary matches the official jTDS URL grammar
What Does This Do
Fixes the port-substring end index in
JDBCConnectionUrlParser.doParse()for JTDS URLs: instead of always usingdbLoc(which is-1when there's no trailing/database), it now falls back toparamLoc(when there are;paramsbut no db) ordetails.length()(barehost:port).Motivation
A JTDS URL of the form
jdbc:jtds:sqlserver://host:1433(host:portwith no trailing/databaseand no;params) hasdbLoc == -1, anddetails.substring(portLoc + 1, dbLoc)threwStringIndexOutOfBoundsException. Found while triaging a production stack trace showing this exception escapingDriverManager.getConnectionup throughJDBCDecorator.Additional Notes
None.
Test plan
JDBCConnectionUrlParserTest.groovy:jdbc:jtds:sqlserver://dbhostname.com:1433andjdbc:jtds:sqlserver://dbhostname.com:1433;user=user;password=pw./gradlew :dd-java-agent:instrumentation:jdbc:test --tests JDBCConnectionUrlParserTestpasses/techdebt— no issues found🤖 Generated with Claude Code