Updated ThreadSafeLazyLoadedivoryTower#583
Conversation
Added null check in private constructor to prevent instantiating by Reflection call
iluwatar
left a comment
There was a problem hiding this comment.
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"
|
@shaiktaj this pull request is about to be closed due to inactivity. Please comment if you are still working on this. |
|
@iluwatar The IllegalStateException is being thrown right? |
|
Thanks @shaiktaj it looks good 👍 |
|
It's still possible to create many instances of the class using only reflection. |
|
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 |
Added null check in private constructor to prevent instantiating by Reflection call