Skip to content

Updated ThreadSafeLazyLoadedivoryTower#583

Merged
iluwatar merged 1 commit into
iluwatar:masterfrom
shaiktaj:patch-1
Aug 12, 2017
Merged

Updated ThreadSafeLazyLoadedivoryTower#583
iluwatar merged 1 commit into
iluwatar:masterfrom
shaiktaj:patch-1

Conversation

@shaiktaj
Copy link
Copy Markdown
Contributor

Added null check in private constructor to prevent instantiating by Reflection call

Added null check in private constructor to prevent instantiating by Reflection call
Copy link
Copy Markdown
Owner

@iluwatar iluwatar left a comment

Choose a reason for hiding this comment

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

The purpose is to prevent instantiation via reflection call but the implementation does not seem to cover all cases. Basically what @igorcadelima said in Gitter earlier:

Igor C. A. de Lima @igorcadelima May 27 18:39
"@shaiktaj a null check wouldn't help. If the program has just started and someone tries to instantiate it via reflection, cool. But what if someone first tries to getInstance and later instantiate via reflection? There should be a null check AND an exception throwing"

@iluwatar
Copy link
Copy Markdown
Owner

@shaiktaj this pull request is about to be closed due to inactivity. Please comment if you are still working on this.

@shaiktaj
Copy link
Copy Markdown
Contributor Author

shaiktaj commented Aug 2, 2017

@iluwatar The IllegalStateException is being thrown right?

@iluwatar iluwatar merged commit 600553e into iluwatar:master Aug 12, 2017
@iluwatar
Copy link
Copy Markdown
Owner

Thanks @shaiktaj it looks good 👍

@igorcadelima
Copy link
Copy Markdown
Contributor

It's still possible to create many instances of the class using only reflection.

@iluwatar
Copy link
Copy Markdown
Owner

It is not a complete solution, but a step in the right direction. See https://stackoverflow.com/questions/6994393/singleton-how-to-stop-create-instance-via-reflection/6994437

@iluwatar iluwatar modified the milestone: 1.19.0 Feb 17, 2018
crakdelpol pushed a commit to crakdelpol/java-design-patterns that referenced this pull request Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants