New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add customized NPE for null actor system #23580
Conversation
Can one of the repo owners verify this patch? |
OK TO TEST |
Test PASSed. |
@@ -74,7 +74,9 @@ trait ExtensionId[T <: Extension] { | |||
/** | |||
* Returns an instance of the extension identified by this ExtensionId instance. | |||
*/ | |||
def apply(system: ActorSystem): T = system.registerExtension(this) | |||
def apply(system: ActorSystem): T = { | |||
java.util.Objects.requireNonNull(system, "Null system!").registerExtension(this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
system must not be
null!
?
LGTM, proposed slight rewording (can make the change if you think it's ok) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with ktosos wording
Test PASSed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I'd say this is the responsibility of the caller, but this might be a relatively common case and it doesn't cost anything to produce a better message here, so 👍
Assigned milestone |
* Add customized NPE for null actor system * "system must not be null!"
* Add customized NPE for null actor system * "system must not be null!"
Change
Add a customized NPE that indicates that the passed in actor system was null here. IllegalArgumentException would also be appropriate.
Rationale
In the HttpApp, there are various hooks that are provided for a running server:
http://doc.akka.io/docs/akka-http/current/scala/http/routing-dsl/HttpApp.html#providing-your-own-actor-system
However, the access to the actor system is controlled by systemReference, which can be null. If you try accessing
CoordinatedShutdown(systemReference.get())
you'll getWhich does not indicate that a null actor system was passed in unless you look at the source code.