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
SLING-11831 - Allow setting job properties for custom job state #26
Conversation
src/main/java/org/apache/sling/event/impl/jobs/queues/JobExecutionContextImpl.java
Outdated
Show resolved
Hide resolved
@Override | ||
public void setProperty(final String name, final Object value) { | ||
if ( name == null ) { | ||
throw new IllegalArgumentException("Name must not be null"); |
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.
Optional, this could be simplfied with:
Objects.requireNonNull(name, "Name must not be null")
But this would throw a NPE (with the supplied message) rather that an IllegalArgumentMessage.
https://docs.oracle.com/javase/8/docs/api/java/util/Objects.html#requireNonNull-T-java.lang.String-
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.
Since it is a user facing API, I implemented it opting for IllegalArgumentException as the exception type. Do you agree or should I change it and allow it to be an NPE?
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.
We could also add a @NotNull annotation to the API to make it more visible.
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.
I'm okay with keeping the current code to have a more descriptive error, but I agree with @joerghoh regarding the annotations.
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.
I had thought of using @NonNull
too, but it meant I need to introduce a new dependency to this project and org.apache.sling.event.api project. WDYT?
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
Also, note that @Nonnull
isn't perfect at blocking null parameters from getting passed, so it still makes sense to keep the null checks. See here for details:
https://stackoverflow.com/questions/13484202/how-to-use-nullable-and-nonnull-annotations-more-effectively/46290602#46290602
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.
we use other null annotations in Sling: https://sling.apache.org/documentation/development/null-analysis.html
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.
Thanks @kwin, I will use those.
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.
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
Add setProperty to the JobExecutionContext for adding custom properties.