Skip to content

Conversation

@smile-ab
Copy link
Contributor

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

Issue:
#3202

@github-actions
Copy link

github-actions bot commented Mar 10, 2025

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

Copy link

@github-actions github-actions bot left a comment

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
Copy link

@github-actions github-actions bot left a comment

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

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
2 checks passed
@iluwatar
Copy link
Owner

Looks good! Thank you for the contribution 🎉

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

@allcontributors
Copy link
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