bytedeco/javacpp

Simplify and clean-up javacpp.Loader

Open

#514 opened on Aug 29, 2021

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Java (620 forks)batch import
enhancementhelp wanted

Repository metrics

Stars
 (4,279 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

While working on the current OSGi issue in javacpp I read a lot through the javacpp.Loader and I have to admit, that it is sometimes hard to read and to understand this class. Not only because the class is very large but also because the big important methods (like findResources(), cacheResources(), ...) itself are complex monoliths that also sometimes repetitive code. For example SonarLint indicates a cognitive complexity of 141 for loadLibrary() and three other methods are close to to or above 100 while at most 15 is recommended. The exact numbers may be arguable, but those number underline my subjective impression.

Therefore I want to suggest to simplify and clean-up the javacpp.Loader in the following ways:

  • split-up long monolithic methods into multiple (private) ones where suitable
  • extract repetitive expressions into methods (mainly when they are used as arguments of if-statements)
  • use try with resources (Exceptions while closing could be handled like other exceptions)
  • use generic type arguments (for parametrized types, mainly Class<?>, even if it is only a wildcard.
  • use the diamond operator where applicable, to not specific generic-type arguments unnecessarily and maybe some more minor improvements/simplifications.

If you are interested in such simplifications/clean-ups I would be happy to provide a corresponding PR.

Contributor guide