Skip to content
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

Merged
merged 4 commits into from May 3, 2023

Conversation

andrewmkhoury
Copy link
Contributor

Add setProperty to the JobExecutionContext for adding custom properties.

@Override
public void setProperty(final String name, final Object value) {
if ( name == null ) {
throw new IllegalArgumentException("Name must not be null");
Copy link
Contributor

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-

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@joerghoh joerghoh left a comment

Choose a reason for hiding this comment

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

LGTM

@klcodanr klcodanr merged commit 1cb0ae2 into apache:master May 3, 2023
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants