Skip to content

Fix CodeQL note-severity alerts: confusing overloads with subtype parameters - #840

Merged
vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:codeql/confusing-signature
Aug 4, 2026
Merged

Fix CodeQL note-severity alerts: confusing overloads with subtype parameters#840
vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:codeql/confusing-signature

Conversation

@vharseko

@vharseko vharseko commented Aug 3, 2026

Copy link
Copy Markdown
Member

Addresses the java/confusing-method-signature alerts. Most of them cannot be acted on, but the ones which can were worth looking at: one was a latent StackOverflowError.

A recursive overload which could never have worked

AbstractPBKDF2PasswordStorageScheme had two overloads whose parameter types are related by inheritance:

private SecretKey encodeWithRandomSalt(ByteString plaintext, byte[] saltBytes, int iterations) {
    random.nextBytes(saltBytes);
    return encodeWithRandomSalt(plaintext, saltBytes, iterations);   // plaintext is a ByteString...
}                                                                     // ...so this calls itself

private SecretKey encodeWithRandomSalt(ByteSequence plaintext, byte[] saltBytes, int iterations) {
    random.nextBytes(saltBytes);
    return encodeWithSalt(plaintext, saltBytes, iterations);
}

ByteString implements ByteSequence, so inside the first overload the most specific applicable method is itself: any call would have recursed until the stack was exhausted. It survived because it is dead code — encodePassword() and encodeAuthPassword() both pass a ByteSequence and bind to the second overload. The dead overload is removed.

While there, the file received the license header it was missing. Its original attribution is left to the maintainers: the file was contributed in 2022 without a header, and this change does not invent one.

Overloads selected by the static type in the replication CLI

ReplicationCliMain overloaded two private methods on MonoServerReplicationUserData and on three of its subtypes (DisableReplicationUserData, StatusReplicationUserData, PurgeHistoricalUserData), so which method runs depends on the declared type of the variable rather than on the object. The two general overloads are renamed after what they actually do — they prompt through sourceServerCI and read the source server arguments:

  • getConnection(MonoServerReplicationUserData)getConnectionToSourceServer(...)
  • initializeWithArgParser(MonoServerReplicationUserData)initializeWithArgParserForSourceServer(...)

The compiler identified every call site of both: initialize-all, pre and post external initialization, and status.

Alerts deliberately left open (33)

  • 10 — the implementation of the SLF4J Logger interface in OpenDJLoggerAdapter (trace/debug/info/warn/error(String, Object) next to (String, Throwable)): the shape is imposed by the interface.
  • ~19 — public overload sets of the SDK and of the plugin API: Connection.add(Entry|AddRequest), ChangeRecordWriter.writeChangeRecord(...) (four), Responses.newSearchResultEntry, LDIF.toLDIF, ByteStringBuilder.appendBytes, Converters.to/from (three), DirectoryServerPlugin.isConfigurationAcceptable, MonitorData.add, OperationContext.getCSN, SNMPMonitor.counter32Value/gauge32Value, AbstractIndexTableModel.compareNames, TemplateValue.append and the two menu callbacks of ManageTasks. Renaming any of them is an API break.
  • 2SASLBindClientImpl.handle(ChoiceCallback) and handle(TextInputCallback): two members of a deliberate family of eight handle(XxxCallback) methods which handle(Callback[]) dispatches to; renaming two of the eight would make the family inconsistent.
  • 2ConsistentHashDistributionLoadBalancer.synchronize(SearchResultHandler|IntermediateResponseHandler): the parameter types are unrelated, so no call can select the wrong one.

Testing

opendj-server-legacy (-Pprecommit): PKCS5S2PasswordStorageSchemeTestCase (53), PBKDF2PasswordStorageSchemeTestCase (39), PBKDF2HmacSHA256PasswordStorageSchemeTestCase (39), PBKDF2HmacSHA512PasswordStorageSchemeTestCase (39) — 170 tests, all passing. The password storage schemes are the only place where code was removed; the replication CLI changes are private renames, verified by the compiler.

…ameters

Most of the java/confusing-method-signature alerts are on public overload sets
of the SDK, on the implementation of the SLF4J Logger interface and on the
deliberate handle(XxxCallback) dispatch family of SASLBindClientImpl, where the
shape of the API cannot change. The ones which remain are private methods whose
parameter types are related by inheritance, so that the overload is chosen from
the static type of the variable, and one of them was a latent StackOverflowError:

* AbstractPBKDF2PasswordStorageScheme had encodeWithRandomSalt(ByteString, ..)
  next to encodeWithRandomSalt(ByteSequence, ..). Since ByteString implements
  ByteSequence, the body of the first one called itself rather than the second,
  so any call would have recursed until the stack was exhausted. It was dead
  code: both callers pass a ByteSequence and bind to the other overload. It is
  removed. The file was also missing its license header.
* ReplicationCliMain overloaded getConnection() and initializeWithArgParser() on
  MonoServerReplicationUserData and on three of its subtypes, so a variable
  declared with the base type silently selected the general method. The general
  ones are renamed to getConnectionToSourceServer() and
  initializeWithArgParserForSourceServer(), which is what they do: they prompt
  through sourceServerCI and read the source server arguments. The compiler
  identified every call site: initialize-all, pre and post external
  initialization, and status.
@vharseko
vharseko requested a review from maximthomas August 3, 2026 20:50
@vharseko vharseko added security Security fixes / CodeQL code-scanning alerts java Pull requests that update java code bug labels Aug 3, 2026
@vharseko
vharseko merged commit a0a2b0b into OpenIdentityPlatform:master Aug 4, 2026
17 checks passed
@vharseko
vharseko deleted the codeql/confusing-signature branch August 4, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug java Pull requests that update java code security Security fixes / CodeQL code-scanning alerts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants