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

Make DefaultPluginDescriptor#addDependency usable #398

Merged

Conversation

rreich
Copy link
Contributor

@rreich rreich commented Sep 24, 2020

Do not use Collections.emptyList() to create empty lists that should be writable,
otherwise an UnsupportedOperationException is thrown when you try to add something to that list.

This is especially annoying as it is not easy to fix in a subclass because of the asynchronous setter and getter of dependencies (Is that really a good idea?).

Do not use Collections.emptyList() to create empty lists that should be writable,
otherwise an UnsupportedOperationException is thrown when you try to add something to that list.
@rreich
Copy link
Contributor Author

rreich commented Sep 24, 2020

First of all, thanks for your great library!
I just stumbled across this little bug and thought I create a quick PR - I didn't create an extra issue though. Hope that's ok.
Cheers,
Rainer

@decebals
Copy link
Member

decebals commented Sep 24, 2020

I use method Collections.emptyList() intentionally and I know that the returned list is immutable.
Do you have an use case when you need a non immutable list?

@rreich
Copy link
Contributor Author

rreich commented Sep 25, 2020

Yes I have a usecase. We extended the framework a bit and introduced something we called "add-ons", which are plugins that extend other plugins. To keep changes minimal, I add dependencies of add-ons programatically to the extended plugins to make use of the built-in plugin resolution / ordering, which works nicely.

But besides my usecase, you already provide the method addDependency(), which does not work when the dependencies list is empty. If you do not want to allow adding dependencies, this method should be removed (which of course is not my intent).

@decebals
Copy link
Member

But besides my usecase, you already provide the method addDependency(), which does not work when the dependencies list is empty. If you do not want to allow adding dependencies, this method should be removed (which of course is not my intent).

@rreich @josiahhaswell Can we reduce the visibility of DefaultPluginDescriptor#addDependency() from public in protected?
For the moment I think that I will merge this PR, to not break the API, but in the future I think that I prefer to make DefaultPluginDescriptor immutable. What do you think?

@rreich
Copy link
Contributor Author

rreich commented Sep 28, 2020

It wouldn't be a problem for me, if addDependency() was protected, as I have my own subclass anyway and can extend visibility there.

If the descriptors were immutable, I could still subclass it and allow adding dependencies, storing the additional dependencies in the subclass, so it shouldn't be a big problem for me - at least if you don't make them final.

Normally the descriptors should only represent the information from the plugin's metadata, so I think it would make sense to make them immutable. Extending the dependencies of a plugin is probably a very special use-case.

I noticed one more thing, which I probably don't need after this PR is merged but I think would still be nice is, if a PluginDependency was able to convert itself back into its String representation.

@decebals decebals merged commit 597192b into pf4j:master Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants