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

[CALCITE-6552] Enable CheckerFramework in 'server' module #3939

Closed
wants to merge 19 commits into from

Conversation

julianhyde
Copy link
Contributor

In CALCITE-4199 we enabled CheckerFramework (via annotations and CI jobs) in the 'core' and 'linq4j' modules; this change further enables CheckerFramework in the 'server' module, and fixes all violations.

There are also a large number of 'cosmetic' modifications to improve code quality without changing behavior, including:

  • Replace this.x = x; assert x != null; with this.x = requireNonNull(x); in constructors
  • Replace assert in other code locations where it implements an invariant. We don't use requireNonNull because it throws NullPointerException; we would prefer to throw AssertionError or IllegalStateException
  • Replace x.equals("") and x.size() == 0 with x.isEmpty()
  • Make fields final where possible
  • Make private methods and inner classes static where possible
  • In class Pair<K, V> make the type variables K and V no longer nullable by default (you can make each of them nullable if you need)
  • Always import Objects.requireNonNull, Integer.parseInt, Float.parseFloat, Double.parseDouble, Byte.parseByte, Short.parseShort, Boolean.parseBoolean, Long.parseLong via static import

This PR supersedes #3937

@mihaibudiu
Copy link
Contributor

I imagine many of these conversions are automatically performed.
Would you like some of this code reviewed?
This may cause lots of conflicts if people have work under way.

Copy link
Contributor

@NobiGo NobiGo left a comment

Choose a reason for hiding this comment

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

LGTM.

@julianhyde
Copy link
Contributor Author

@mihaibudiu

Would you like some of this code reviewed?

I see @NobiGo has reviewed and approved. I think we're good.

The vast majority of changes don't require review - there was only one choice to make. In one or two places I had to make a decision; e.g. in MongoEnumerator I added the 3 if ... throw lines, because the alternative, to change the return to @Nullable Object, was inferior:

  @Override public Object current() {
    if (current == null) {
      throw new IllegalStateException();
    }
    return current;
  }

This may cause lots of conflicts if people have work under way.

Agreed. I will minimize conflicts by merging this quickly, and avoiding changes that require discretion. I will probably merge today.

@NobiGo, Thanks for your review.

Copy link

sonarqubecloud bot commented Sep 3, 2024

@julianhyde julianhyde closed this in b1308fe Sep 3, 2024
olivrlee pushed a commit to olivrlee/calcite that referenced this pull request Sep 26, 2024
In [CALCITE-4199] we enabled CheckerFramework (via
annotations and CI jobs) in the 'core' and 'linq4j' modules;
this change further enables CheckerFramework in the 'server'
module, and fixes all violations.

There are also a large number of 'cosmetic' modifications to
improve code quality without changing behavior, including:
 * Replace `this.x = x; assert x != null;` with
   `this.x = requireNonNull(x);` in constructors
 * Replace `assert` in other code locations where it
   implements an invariant. We don't use `requireNonNull`
   because it throws `NullPointerException`; we would prefer
   to throw `AssertionError` or `IllegalStateException`
 * Replace `x.equals("")` and `x.size() == 0` with `x.isEmpty()`
 * Make fields `final` where possible
 * Make private methods and inner classes `static` where possible
 * In class `Pair<K, V>` make the type variables `K` and `V`
   no longer nullable by default (you can make each of them
   nullable if you need)
 * Always import `Objects.requireNonNull`, `Integer.parseInt`,
   `Float.parseFloat`, `Double.parseDouble`, `Byte.parseByte`,
   `Short.parseShort`, `Boolean.parseBoolean`, `Long.parseLong`
   via static import, and change autostyle rules to enforce
   this automatically
 * Remove redundant 'throws' clauses
 * Add `@Nullable` annotations for method parameters and
   return values so that types are nullable only if they
   need to be; the goal is that you should not pass null or
   a nullable value as an argument that has non-nullable
   type, and after this change we are nearer to that goal

In Util, optimize methods `transform` and `transformIndexed`
for the case where list is empty and immutable.

Close apache#3939
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.

3 participants