Skip to content

chore: #2058 Handle the boolean returned by File.delete - #2067

Merged
lbroudoux merged 3 commits into
microcks:masterfrom
Heyy-Himanshuu:chore/2058-handle-file-delete-results
May 4, 2026
Merged

lbroudoux merged 3 commits into
microcks:masterfrom
Heyy-Himanshuu:chore/2058-handle-file-delete-results

Conversation

@Heyy-Himanshuu

Copy link
Copy Markdown
Contributor

Sonar flagged four cleanup sites that call File.delete() but ignore the boolean return value (rule java:S899). When delete() returns false the file silently survives, which over time produces disk leaks of trust stores, resolved references, and uploaded artifacts. Each site now logs a warning when delete() fails so the leak is diagnosable from production logs.

Description

  • minions/async — WebSocketMessageConsumptionTask#close (L128): warn when the WebSocket trust store cannot be deleted.
  • webapp — ReferenceResolver#cleanResolvedReferences (L187): warn for each resolved reference file that fails to delete.
  • webapp — UploadArtifactController#importArtifactFromUrl (L111): warn when the temporary artifact downloaded from a URL cannot be deleted in the finally block.
  • webapp — UploadArtifactController#importArtifact (L156): same for the multipart-uploaded artifact.
  • UploadArtifactController uses a SafeLogger whose warn(...) overloads only accept (String) and (String, Throwable), so the warning is emitted via plain string concatenation rather than slf4j placeholder substitution.
  • Behaviour is unchanged on the happy path; failed deletions previously produced no signal at all.
  • mvn spotless:check -pl minions/async,webapp passes locally.

Related issue(s)

See also #2058

Sonar flagged four cleanup sites that call File.delete() but ignore
the boolean return value (rule java:S899). When delete() returns
false the file silently survives, which over time can produce disk
leaks of trust stores, resolved references, and uploaded artifacts.
Each site now logs a warning when delete() fails so the leak becomes
diagnosable from production logs.

- minions/async WebSocketMessageConsumptionTask#close (L128): warn
  when the WebSocket trust store cannot be deleted.
- webapp ReferenceResolver#cleanResolvedReferences (L187): warn for
  each resolved reference file that fails to delete.
- webapp UploadArtifactController#importArtifactFromUrl (L111): warn
  when the temporary artifact downloaded from a URL cannot be
  deleted in the finally block.
- webapp UploadArtifactController#importArtifact (L156): same for
  the multipart-uploaded artifact.

UploadArtifactController uses a SafeLogger whose warn(...) overloads
only accept (String) and (String, Throwable), so the warning is
emitted via plain string concatenation rather than slf4j placeholder
substitution. Behaviour is unchanged on the happy path; failed
deletions previously produced no signal at all.

Signed-off-by: Git-HimanshuRathi <[email protected]>
The previous commit used slf4j-style '{}' placeholder syntax with
WebSocketMessageConsumptionTask's JBoss Logger, which only exposes
warn(Object), warn(Object, Throwable) and warn(Object, Object[]) -
no (String, Object) overload - so CI compilation failed.

Switch to JBoss Logger#warnf with printf-style '%s', matching the
existing convention in the same file (e.g. logger.errorf at L98).

Signed-off-by: Git-HimanshuRathi <[email protected]>

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small change to avoid future issues about not using the templatized form of log messages. Thanks a lot!

@lbroudoux lbroudoux added kind/task java Pull requests that update Java code labels May 4, 2026
@lbroudoux lbroudoux added this to the 1.15.0 milestone May 4, 2026
…ilures

@lbroudoux's review on this PR pointed out that the warning emitted
on File.delete() failure should use SafeLogger's templated form with
'{}' rather than string concatenation, to stay consistent with the
rest of the file.

SafeLogger.warn(...) only exposed (String) and (String, Throwable) -
the placeholder overloads existed for debug, info and error but not
for warn. Add the three missing warn overloads ((String, Object),
(String, Object, Object) and (String, Object...)), each going through
the existing encode(...) sanitiser exactly like the equivalent info
overloads, so user-controlled data still gets newline-encoded before
being passed down to the underlying SLF4J logger.

Switch the two File.delete() warning sites in UploadArtifactController
to the '{}' templated form now that the API supports it.

Signed-off-by: Git-HimanshuRathi <[email protected]>

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lbroudoux
lbroudoux merged commit 80e5025 into microcks:master May 4, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Pull requests that update Java code kind/task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants