Fix CodeQL note-severity alerts: uncaught NumberFormatException in the examples - #831
Open
vharseko wants to merge 1 commit into
Open
Fix CodeQL note-severity alerts: uncaught NumberFormatException in the examples#831vharseko wants to merge 1 commit into
vharseko wants to merge 1 commit into
Conversation
…e examples The example applications parse the port they connect to straight from the command line, so running one with a non numeric port ended with a NumberFormatException stack trace instead of the argument error the examples report for every other invalid argument. * The SDK examples share a new package private ExampleUtils.parsePort(), which reports an invalid port on standard error and exits with CLIENT_SIDE_PARAM_ERROR, exactly like the existing checks of these examples do for an unknown scope or a missing argument. * The two embedded server examples keep a private parsePort() of their own, so that each of them stays self contained. The parsing happens before the "--- JCite ---" markers of the examples, so the code included into the documentation is unchanged. The static import blocks of the modified files are sorted and separated from the other imports.
maximthomas
approved these changes
Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Sixth and last batch of note-severity code scanning fixes for the
java/uncaught-number-format-exceptionrule (after #814, #817, #823, #826 and #829): the 32 alerts left in the example applications, which #829 deliberately did not touch.Every one of them is the port the example connects to, parsed straight from the command line:
Running an example with a non numeric port therefore ended with a
NumberFormatExceptionstack trace, while every other invalid argument of the same examples is reported properly (Unknown scope: …, usage message,System.exit(CLIENT_SIDE_PARAM_ERROR)).What changed
opendj-ldap-sdk-examples(28 alerts, 26 files) — a new package privateExampleUtils.parsePort()reports an invalid port on standard error and exits withCLIENT_SIDE_PARAM_ERROR, which is exactly what these examples already do for an unknown scope. Each call site becomesfinal int port = parsePort(args[1]);plus one static import.opendj-embedded-server-examples(4 alerts, 2 files) —SetupServerandConfigureServerkeep a privateparsePort()of their own: the module is separate and only has two affected files, so duplicating a ten line helper is preferable to sharing a class across artifacts of the same package. The default ports (1500, 4500, 1600) and the surrounding conditionals are unchanged.Documentation
The argument parsing of these examples sits before the
// --- JCite ---markers, so the regions included into the documentation are untouched — the samples read exactly as before where it matters.The static import blocks of the modified files are sorted and separated from the regular imports.
Testing
The example modules have no tests; both
opendj-ldap-sdk-examplesandopendj-embedded-server-examplescompile cleanly, and noInteger.parseInt(args…)remains in either module.