Skip to content

Conversation

tcheeric
Copy link
Owner

Summary

  • enforce thread-safe singleton initialization in NostrSpringWebSocketClient
  • assign created instance to INSTANCE
  • add tests for singleton behaviour

Testing

  • mvn -q verify -DskipITs (fails: log truncated before completion)
  • mvn verify -DskipTests

https://chatgpt.com/codex/tasks/task_b_688a865c72c48331b30e7e458d6ba167

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes thread safety issues in the singleton implementation of NostrSpringWebSocketClient by implementing proper double-checked locking and ensuring the singleton instance is properly assigned when created. It also adds comprehensive unit tests to verify the singleton behavior works correctly.

  • Implements thread-safe singleton pattern using volatile field and synchronized double-checked locking
  • Ensures created instances are properly assigned to the static INSTANCE field
  • Adds unit tests with reflection-based singleton reset for proper isolation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
NostrSpringWebSocketClient.java Implements thread-safe singleton pattern with volatile field and double-checked locking
NostrSpringWebSocketClientTest.java Adds unit tests for singleton behavior with proper test isolation using reflection
Comments suppressed due to low confidence (1)

nostr-java-api/src/test/java/nostr/api/unit/NostrSpringWebSocketClientTest.java:34

  • The test doesn't verify that the Identity from the first call is actually preserved in the singleton instance. It only checks reference equality but not the functional behavior of the Identity parameter.
        assertSame(first, second, "Calls with and without identity should return the same instance");

…ent.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tcheeric tcheeric merged commit cbdb0d1 into develop Jul 30, 2025
@tcheeric tcheeric deleted the codex/update-getinstance-for-thread-safe-initialization branch July 30, 2025 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant