Skip to content

Fix Singleton typo and extend reflection handling to remaining implementations - #3203

Merged
iluwatar merged 2 commits into
iluwatar:masterfrom
smile-ab:singleton-typo-and-reflection-handling
Mar 18, 2025
Merged

Fix Singleton typo and extend reflection handling to remaining implementations#3203
iluwatar merged 2 commits into
iluwatar:masterfrom
smile-ab:singleton-typo-and-reflection-handling

Conversation

@smile-ab

Copy link
Copy Markdown
Contributor

Description:
Fix typo and extend reflection handling for remaining implementations for the Singleton pattern

Issue:
#3202

@github-actions

github-actions Bot commented Mar 10, 2025

Copy link
Copy Markdown

PR Summary

This PR fixes a typo and extends reflection handling to several Singleton implementations. It adds exception handling to prevent instantiation via reflection in BillPughImplementation, InitializingOnDemandHolderIdiom, and IvoryTower. Additionally, it includes new tests for reflection-based instantiation in SingletonTest and EnumIvoryTowerTest.

Changes

File Summary
singleton/src/main/java/com/iluwatar/singleton/BillPughImplementation.java Added exception handling to the private constructor to prevent instantiation via reflection. Throws IllegalStateException if already initialized.
singleton/src/main/java/com/iluwatar/singleton/InitializingOnDemandHolderIdiom.java Added exception handling to the private constructor to prevent instantiation via reflection. Throws IllegalStateException if already initialized.
singleton/src/main/java/com/iluwatar/singleton/IvoryTower.java Added exception handling to the private constructor to prevent instantiation via reflection. Throws IllegalStateException if already initialized.
singleton/src/test/java/com/iluwatar/singleton/EnumIvoryTowerTest.java Added a test case to verify that creating a new instance via reflection throws an exception. Uses assertThrows to check for ReflectiveOperationException.
singleton/src/test/java/com/iluwatar/singleton/SingletonTest.java Added a test case to verify that creating a new instance via reflection throws an exception. Uses assertThrows to check for InvocationTargetException.
singleton/src/test/java/com/iluwatar/singleton/ThreadSafeDoubleCheckLockingTest.java No changes were made to the functionality of this file.

autogenerated by presubmit.ai

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!

Review Summary

Commits Considered (2)
  • b8ea511: adding Reflection handling to other Singleton implementations
  • d63b5e6: fix typo
Files Processed (6)
  • singleton/src/main/java/com/iluwatar/singleton/BillPughImplementation.java (1 hunk)
  • singleton/src/main/java/com/iluwatar/singleton/InitializingOnDemandHolderIdiom.java (1 hunk)
  • singleton/src/main/java/com/iluwatar/singleton/IvoryTower.java (1 hunk)
  • singleton/src/test/java/com/iluwatar/singleton/EnumIvoryTowerTest.java (2 hunks)
  • singleton/src/test/java/com/iluwatar/singleton/SingletonTest.java (2 hunks)
  • singleton/src/test/java/com/iluwatar/singleton/ThreadSafeDoubleCheckLockingTest.java (2 hunks)
Actionable Comments (0)
Skipped Comments (3)
  • singleton/src/main/java/com/iluwatar/singleton/BillPughImplementation.java [42-46]

    readability: "Remove redundant comment."

  • singleton/src/main/java/com/iluwatar/singleton/InitializingOnDemandHolderIdiom.java [45-49]

    readability: "Remove redundant comment."

  • singleton/src/main/java/com/iluwatar/singleton/IvoryTower.java [35-39]

    readability: "Remove redundant comment."

@smile-ab
smile-ab force-pushed the singleton-typo-and-reflection-handling branch from b8ea511 to 28bb7da Compare March 13, 2025 11:55

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!

Review Summary

Commits Considered (2)
  • 28bb7da: adding Reflection handling to other Singleton implementations
  • 314f273: fix typo
Files Processed (6)
  • singleton/src/main/java/com/iluwatar/singleton/BillPughImplementation.java (1 hunk)
  • singleton/src/main/java/com/iluwatar/singleton/InitializingOnDemandHolderIdiom.java (1 hunk)
  • singleton/src/main/java/com/iluwatar/singleton/IvoryTower.java (1 hunk)
  • singleton/src/test/java/com/iluwatar/singleton/EnumIvoryTowerTest.java (2 hunks)
  • singleton/src/test/java/com/iluwatar/singleton/SingletonTest.java (2 hunks)
  • singleton/src/test/java/com/iluwatar/singleton/ThreadSafeDoubleCheckLockingTest.java (2 hunks)
Actionable Comments (0)
Skipped Comments (3)
  • singleton/src/main/java/com/iluwatar/singleton/BillPughImplementation.java [42-46]

    readability: "Remove redundant comment."

  • singleton/src/main/java/com/iluwatar/singleton/InitializingOnDemandHolderIdiom.java [45-49]

    readability: "Remove redundant comment."

  • singleton/src/main/java/com/iluwatar/singleton/IvoryTower.java [35-39]

    readability: "Remove redundant comment."

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@iluwatar
iluwatar merged commit 19d9d31 into iluwatar:master Mar 18, 2025
@iluwatar

Copy link
Copy Markdown
Owner

Looks good! Thank you for the contribution 🎉

@all-contributors please add @smile-ab for code

@allcontributors

Copy link
Copy Markdown
Contributor

@iluwatar

I've put up a pull request to add @smile-ab! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants