Skip to content

Conversation

@DomGarguilo
Copy link
Member

@DomGarguilo DomGarguilo commented Aug 7, 2025

This PR fixes the warnings from the core module. Here is a description from the ticket:

This warning gets emitted when an exception is thrown within an constructor.

There are several ways to avoid this warning:

  1. make the class final
  2. remove the thrown exception from the constructor
  3. add a finalize() method so it cant be overridden
  4. make the constructor private

There are pros and cons to each fix.

  • making a class final prohibits inheriting it
  • removing the thrown exception usually means forgoing validation
  • adding a finalize() method means we also need to ignore the deprecation warning since finalizer() is deprecated
  • making the constructor private usually takes a lot of refactoring to move to a different pattern to create the object

I think the best approach here is to work through a couple modules at a time and fix these.

I removed omit block from the root pom and instead moved it into each module so that we can just ignore this spotbugs warning until we fix them in each module.

@DomGarguilo DomGarguilo added this to the 4.0.0 milestone Aug 7, 2025
@DomGarguilo DomGarguilo self-assigned this Aug 7, 2025
Copy link
Contributor

@ddanielr ddanielr left a comment

Choose a reason for hiding this comment

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

Moving this check out from the top-level pom to the modules makes sense.

Do we need to make release notes changes for finalizing any of the classes that are defined in our public API?

@DomGarguilo
Copy link
Member Author

Do we need to make release notes changes for finalizing any of the classes that are defined in our public API?

That is a good question. I am not sure.

@DomGarguilo DomGarguilo requested a review from ctubbsii August 8, 2025 16:28
@DomGarguilo
Copy link
Member Author

I think feedback regarding the method of fixing this warning would be helpful (making the class final vs. adding the finalize() method). I tried to only make things final if it was an inner class and/or something that seemed very unlikely to be subclassed, however I just used my best judgement so would like others input on this part.

@ddanielr
Copy link
Contributor

ddanielr commented Aug 8, 2025

Do we need to make release notes changes for finalizing any of the classes that are defined in our public API?

That is a good question. I am not sure.

I think feedback regarding the method of fixing this warning would be helpful (making the class final vs. adding the finalize() method). I tried to only make things final if it was an inner class and/or something that seemed very unlikely to be subclassed, however I just used my best judgement so would like others input on this part.

I don't see an issue with finalizing the default implementation classes since users should be implementing new classes from the interface rather than extending the clientImpl classes.

Since finalize() is deprecated, does this SpotBugs warning go away if we were to switch to a newer java version?

@dlmarion
Copy link
Contributor

dlmarion commented Aug 8, 2025

I think feedback regarding the method of fixing this warning would be helpful (making the class final vs. adding the finalize() method).

I have no issue with making classes final where we can and where it makes sense. I'm not sure adding a finalizer to fix the others is a good long-term approach though it's likely the easiest fix. Finalizers themselves are deprecated and will be removed in a future Java release. I'm wondering if fixing the objects so that they don't throw exceptions from the constructor is the better choice, for example, using an init method on the objects that needs to be called post-construction but before use. There is now a jvm option, --finalization=disabled, in JDK 18 that disables all Finalizers as a step toward removal.

Copy link
Member

@ctubbsii ctubbsii left a comment

Choose a reason for hiding this comment

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

These are pretty broad suppressions. I think it's nice that you're trying to narrow them down and triage them one at a time, but I'm wondering if this should be considered a WIP, or is this the intended final PR?

@DomGarguilo DomGarguilo changed the title Fix ConstructorThrow SpotBugs warnings in core module WIP - Fix ConstructorThrow SpotBugs warnings in core module Aug 13, 2025
@DomGarguilo DomGarguilo changed the title WIP - Fix ConstructorThrow SpotBugs warnings in core module Fix ConstructorThrow SpotBugs warnings in core module Aug 14, 2025
@DomGarguilo
Copy link
Member Author

This PR is no longer a WIP.

To fix these spotbugs warnings I either made the class final (best solution, not possible everywhere) or I added a @SuppressFBWarnings tag to the class.

Copy link
Contributor

@keith-turner keith-turner left a comment

Choose a reason for hiding this comment

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

All the java changes look good, could not really review the maven changes very well though.

@DomGarguilo DomGarguilo requested a review from ctubbsii August 29, 2025 16:14
DomGarguilo and others added 5 commits November 20, 2025 12:04
* remove overly restrictive exception thrown from ContextClassLoaderFactory constructor
* make ColumnSet final since its in an impl package
* remove empty build and plugin blocks from pom (leftover from previous iteration)

Co-authored-by: Christopher Tubbs <ctubbsii@apache.org>
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.

5 participants