You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2024/09/03 20:32:40 UTC

(calcite) branch main updated: [CALCITE-6552] Enable CheckerFramework in 'server' module

This is an automated email from the ASF dual-hosted git repository.

jhyde pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new b1308feff4 [CALCITE-6552] Enable CheckerFramework in 'server' module
b1308feff4 is described below

commit b1308feff49c8b747b3bbb52e1519d334bc984ec
Author: Julian Hyde <jh...@apache.org>
AuthorDate: Tue Aug 27 01:38:06 2024 -0700

    [CALCITE-6552] Enable CheckerFramework in 'server' module
    
    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/calcite#3939
---
 .github/workflows/main.yml                         |   6 +-
 .../adapter/arrow/ArrowFilterEnumerator.java       |  10 +-
 .../apache/calcite/adapter/arrow/ArrowTable.java   |  12 +-
 .../calcite/adapter/arrow/ArrowAdapterTest.java    |   9 +-
 .../org/apache/calcite/test/BabelQuidemTest.java   |   7 +-
 build.gradle.kts                                   |  11 ++
 .../adapter/cassandra/CassandraEnumerator.java     |   4 +-
 .../calcite/adapter/cassandra/CassandraFilter.java |   8 +-
 .../adapter/cassandra/CassandraProject.java        |   9 +-
 .../calcite/adapter/cassandra/CassandraSchema.java |   5 +-
 .../adapter/cassandra/CassandraSchemaFactory.java  |   4 +-
 .../calcite/adapter/cassandra/CassandraSort.java   |   4 +-
 .../calcite/adapter/cassandra/CassandraTable.java  |   6 +-
 .../cassandra/CassandraToEnumerableConverter.java  |  13 +-
 .../apache/calcite/test/CassandraExtension.java    |   8 +-
 core/src/main/codegen/templates/Parser.jj          |   4 +-
 .../main/java/org/apache/calcite/DataContexts.java |   4 +-
 .../calcite/adapter/enumerable/EnumUtils.java      |  12 +-
 .../adapter/enumerable/EnumerableAsofJoin.java     |   8 +-
 .../adapter/enumerable/EnumerableConvention.java   |   4 +-
 .../enumerable/EnumerableInterpretable.java        |   6 +-
 .../adapter/enumerable/EnumerableMergeJoin.java    |  13 +-
 .../enumerable/EnumerableMergeJoinRule.java        |   2 +-
 .../adapter/enumerable/EnumerableMinus.java        |   2 +-
 .../adapter/enumerable/EnumerableTableModify.java  |  12 +-
 .../adapter/enumerable/EnumerableTraitsUtils.java  |  14 +-
 .../adapter/enumerable/EnumerableWindow.java       |   2 +-
 .../calcite/adapter/enumerable/JavaRowFormat.java  |   2 +-
 .../calcite/adapter/enumerable/RexImpTable.java    |   6 +-
 .../enumerable/impl/WinAggAddContextImpl.java      |   3 +-
 .../enumerable/impl/WinAggResultContextImpl.java   |   2 +-
 .../calcite/adapter/java/ReflectiveSchema.java     |  24 ++--
 .../calcite/adapter/jdbc/JdbcCatalogSchema.java    |   8 +-
 .../apache/calcite/adapter/jdbc/JdbcSchema.java    |   7 +-
 .../apache/calcite/adapter/jdbc/JdbcTableScan.java |   3 +-
 .../adapter/jdbc/JdbcToEnumerableConverter.java    |   2 +-
 .../calcite/config/CalciteSystemProperty.java      |   6 +-
 .../main/java/org/apache/calcite/config/Lex.java   |   9 +-
 .../org/apache/calcite/interpreter/Bindables.java  |   7 +-
 .../apache/calcite/interpreter/Interpreter.java    |  21 +--
 .../calcite/interpreter/JaninoRexCompiler.java     |   5 +-
 .../org/apache/calcite/jdbc/CalciteConnection.java |   4 +-
 .../org/apache/calcite/jdbc/CalciteMetaImpl.java   |  16 +--
 .../org/apache/calcite/jdbc/JavaRecordType.java    |   4 +-
 .../org/apache/calcite/materialize/Lattice.java    |   7 +-
 .../apache/calcite/materialize/LatticeSpace.java   |  10 +-
 .../apache/calcite/materialize/LatticeTable.java   |   6 +-
 .../calcite/materialize/MaterializationActor.java  |  12 +-
 .../apache/calcite/materialize/MutableNode.java    |   7 +-
 .../ProfilerLatticeStatisticProvider.java          |   5 +-
 .../java/org/apache/calcite/materialize/Step.java  |   6 +-
 .../java/org/apache/calcite/model/JsonView.java    |   5 +-
 .../org/apache/calcite/model/ModelHandler.java     |   9 +-
 .../apache/calcite/plan/AbstractRelOptPlanner.java |  42 +++---
 .../java/org/apache/calcite/plan/Contexts.java     |   7 +-
 .../org/apache/calcite/plan/RelCompositeTrait.java |   5 +-
 .../org/apache/calcite/plan/RelOptCluster.java     |   9 +-
 .../org/apache/calcite/plan/RelOptLattice.java     |   5 +-
 .../apache/calcite/plan/RelOptMaterialization.java |  15 +-
 .../apache/calcite/plan/RelOptPredicateList.java   |  12 +-
 .../java/org/apache/calcite/plan/RelOptQuery.java  |   4 +-
 .../java/org/apache/calcite/plan/RelOptRule.java   |   8 +-
 .../org/apache/calcite/plan/RelOptRuleOperand.java |  22 +--
 .../java/org/apache/calcite/plan/RelOptSchema.java |   4 +-
 .../java/org/apache/calcite/plan/RelOptUtil.java   |  60 ++++----
 .../main/java/org/apache/calcite/plan/RelRule.java |  18 +--
 .../java/org/apache/calcite/plan/RelTraitSet.java  |   4 +-
 .../apache/calcite/plan/RexImplicationChecker.java |   2 +-
 .../apache/calcite/plan/SubstitutionVisitor.java   |  69 +++++----
 .../org/apache/calcite/plan/hep/HepRuleCall.java   |   4 +-
 .../plan/visualizer/InputExcludedRelWriter.java    |   5 +-
 .../calcite/plan/visualizer/NodeUpdateHelper.java  |   2 +-
 .../plan/visualizer/RuleMatchVisualizer.java       |  37 +++--
 .../calcite/plan/volcano/IterativeRuleDriver.java  |   4 +-
 .../org/apache/calcite/plan/volcano/RelSet.java    |   5 +-
 .../org/apache/calcite/plan/volcano/RelSubset.java |   4 +-
 .../calcite/plan/volcano/TopDownRuleDriver.java    |   4 +-
 .../calcite/plan/volcano/VolcanoPlanner.java       |  29 ++--
 .../calcite/prepare/CalciteCatalogReader.java      |  12 +-
 .../apache/calcite/prepare/CalcitePrepareImpl.java |  12 +-
 .../org/apache/calcite/prepare/PlannerImpl.java    |   4 +-
 .../java/org/apache/calcite/prepare/Prepare.java   |   7 +-
 .../org/apache/calcite/rel/AbstractRelNode.java    |  21 ++-
 .../org/apache/calcite/rel/RelDistributions.java   |   4 +-
 .../org/apache/calcite/rel/RelFieldCollation.java  |   6 +-
 .../apache/calcite/rel/convert/ConverterImpl.java  |   2 +-
 .../apache/calcite/rel/convert/ConverterRule.java  |   6 +-
 .../org/apache/calcite/rel/core/Aggregate.java     |   4 +-
 .../org/apache/calcite/rel/core/AggregateCall.java |   2 +-
 .../org/apache/calcite/rel/core/CorrelationId.java |   4 +-
 .../java/org/apache/calcite/rel/core/EquiJoin.java |  11 +-
 .../java/org/apache/calcite/rel/core/Exchange.java |   5 +-
 .../java/org/apache/calcite/rel/core/Join.java     |   6 +-
 .../java/org/apache/calcite/rel/core/JoinInfo.java |  10 +-
 .../java/org/apache/calcite/rel/core/Match.java    |  15 +-
 .../java/org/apache/calcite/rel/core/Project.java  |   8 +-
 .../org/apache/calcite/rel/core/RepeatUnion.java   |   5 +-
 .../java/org/apache/calcite/rel/core/Snapshot.java |   3 +-
 .../java/org/apache/calcite/rel/core/Sort.java     |   7 +-
 .../org/apache/calcite/rel/core/SortExchange.java  |   4 +-
 .../java/org/apache/calcite/rel/core/Spool.java    |   7 +-
 .../apache/calcite/rel/core/TableFunctionScan.java |   2 +-
 .../org/apache/calcite/rel/core/TableModify.java   |  16 ++-
 .../org/apache/calcite/rel/core/TableScan.java     |   5 +-
 .../org/apache/calcite/rel/core/TableSpool.java    |   4 +-
 .../org/apache/calcite/rel/core/Uncollect.java     |   4 +-
 .../java/org/apache/calcite/rel/core/Values.java   |   4 +-
 .../calcite/rel/externalize/RelDotWriter.java      |   4 +-
 .../apache/calcite/rel/externalize/RelJson.java    |   7 +-
 .../calcite/rel/externalize/RelWriterImpl.java     |   2 +-
 .../calcite/rel/externalize/RelXmlWriter.java      |   2 +-
 .../calcite/rel/hint/CompositeHintPredicate.java   |  12 +-
 .../org/apache/calcite/rel/hint/HintStrategy.java  |   6 +-
 .../apache/calcite/rel/hint/HintStrategyTable.java |   4 +-
 .../java/org/apache/calcite/rel/hint/Hintable.java |   6 +-
 .../calcite/rel/hint/NodeTypeHintPredicate.java    |   8 +-
 .../java/org/apache/calcite/rel/hint/RelHint.java  |  30 ++--
 .../calcite/rel/logical/LogicalAsofJoin.java       |   3 +-
 .../apache/calcite/rel/logical/LogicalFilter.java  |   4 +-
 .../apache/calcite/rel/logical/LogicalJoin.java    |   3 +-
 .../apache/calcite/rel/logical/LogicalWindow.java  |   5 +-
 .../rel/metadata/JaninoRelMetadataProvider.java    |   9 +-
 .../metadata/ReflectiveRelMetadataProvider.java    |   4 +-
 .../calcite/rel/metadata/RelMdCollation.java       |   5 +-
 .../calcite/rel/metadata/RelMdColumnOrigins.java   |  10 +-
 .../calcite/rel/metadata/RelMdDistribution.java    |   5 +-
 .../rel/metadata/RelMdPercentageOriginalRows.java  |   2 +-
 .../calcite/rel/metadata/RelMdPredicates.java      |   4 +-
 .../calcite/rel/metadata/RelMdSelectivity.java     |   2 +-
 .../calcite/rel/metadata/RelMdUniqueKeys.java      |  20 +--
 .../org/apache/calcite/rel/metadata/RelMdUtil.java |  12 +-
 .../calcite/rel/metadata/RelMetadataQuery.java     |   2 +-
 .../org/apache/calcite/rel/mutable/MutableRel.java |   9 +-
 .../calcite/rel/rel2sql/RelToSqlConverter.java     |   5 +-
 .../apache/calcite/rel/rel2sql/SqlImplementor.java |  28 ++--
 .../AggregateExpandDistinctAggregatesRule.java     |  11 +-
 .../rules/AggregateExpandWithinDistinctRule.java   |  11 +-
 .../calcite/rel/rules/AggregateMergeRule.java      |   2 +-
 .../rel/rules/AggregateReduceFunctionsRule.java    |   6 +-
 .../apache/calcite/rel/rules/CalcRelSplitter.java  |  54 +++----
 .../apache/calcite/rel/rules/FilterJoinRule.java   |  23 ++-
 .../rel/rules/JoinAddRedundantSemiJoinRule.java    |   2 +-
 .../rules/JoinPushTransitivePredicatesRule.java    |   4 +-
 .../calcite/rel/rules/JoinToMultiJoinRule.java     |  27 ++--
 .../org/apache/calcite/rel/rules/LoptJoinTree.java |   7 +-
 .../apache/calcite/rel/rules/LoptMultiJoin.java    |  24 ++--
 .../calcite/rel/rules/LoptOptimizeJoinRule.java    |  14 +-
 .../calcite/rel/rules/LoptSemiJoinOptimizer.java   |   4 +-
 .../rel/rules/MultiJoinOptimizeBushyRule.java      |   5 +-
 .../calcite/rel/rules/ProjectTableScanRule.java    |   4 +-
 .../apache/calcite/rel/rules/PruneEmptyRules.java  |   8 +-
 .../apache/calcite/rel/rules/PushProjector.java    |  37 +++--
 .../calcite/rel/rules/ReduceDecimalsRule.java      |   5 +-
 .../rel/rules/SortProjectTransposeRule.java        |   5 +-
 .../calcite/rel/rules/SortRemoveRedundantRule.java |   2 +-
 .../calcite/rel/rules/SubQueryRemoveRule.java      |  11 +-
 .../apache/calcite/rel/rules/ValuesReduceRule.java |   6 +-
 .../calcite/rel/type/RelDataTypeFactory.java       |   5 +-
 .../calcite/rel/type/RelDataTypeFactoryImpl.java   |  18 ++-
 .../apache/calcite/rel/type/RelDataTypeImpl.java   |  22 +--
 .../org/apache/calcite/rel/type/RelRecordType.java |   4 +-
 .../java/org/apache/calcite/rex/RexBuilder.java    |  28 ++--
 .../main/java/org/apache/calcite/rex/RexCall.java  |   5 +-
 .../org/apache/calcite/rex/RexCorrelVariable.java  |   4 +-
 .../java/org/apache/calcite/rex/RexLambda.java     |   4 +-
 .../java/org/apache/calcite/rex/RexLiteral.java    |  31 +++--
 .../java/org/apache/calcite/rex/RexLocalRef.java   |   5 +-
 .../main/java/org/apache/calcite/rex/RexOver.java  |   4 +-
 .../org/apache/calcite/rex/RexProgramBuilder.java  |  14 +-
 .../java/org/apache/calcite/rex/RexShuttle.java    |   5 +-
 .../java/org/apache/calcite/rex/RexSimplify.java   |  11 +-
 .../main/java/org/apache/calcite/rex/RexUtil.java  |  23 ++-
 .../java/org/apache/calcite/rex/RexVariable.java   |   8 +-
 .../java/org/apache/calcite/rex/RexWindow.java     |  14 +-
 .../org/apache/calcite/rex/RexWindowBounds.java    |  14 +-
 .../java/org/apache/calcite/runtime/Automaton.java |  17 ++-
 .../apache/calcite/runtime/AutomatonBuilder.java   |   5 +-
 .../org/apache/calcite/runtime/BufferStyle.java    |   4 +-
 .../calcite/runtime/CalciteContextException.java   |   5 +-
 .../calcite/runtime/DeterministicAutomaton.java    |  12 +-
 .../org/apache/calcite/runtime/Enumerables.java    |   5 +-
 .../java/org/apache/calcite/runtime/HttpUtils.java |   6 +-
 .../org/apache/calcite/runtime/JsonFunctions.java  |  21 ++-
 .../java/org/apache/calcite/runtime/Matcher.java   |   9 +-
 .../java/org/apache/calcite/runtime/Pattern.java   |   7 +-
 .../java/org/apache/calcite/runtime/Resources.java |  20 +--
 .../apache/calcite/runtime/SocketFactoryImpl.java  |   2 +-
 .../calcite/runtime/SpatialTypeFunctions.java      |   7 +-
 .../apache/calcite/runtime/SpatialTypeUtils.java   |   4 +-
 .../org/apache/calcite/runtime/SqlFunctions.java   |  34 +++--
 .../calcite/schema/impl/ModifiableViewTable.java   |   4 +-
 .../org/apache/calcite/schema/impl/StarTable.java  |   5 +-
 .../java/org/apache/calcite/sql/SqlAccessType.java |  15 +-
 .../org/apache/calcite/sql/SqlAggFunction.java     |   6 +-
 .../java/org/apache/calcite/sql/SqlBasicCall.java  |   7 +-
 .../apache/calcite/sql/SqlBasicTypeNameSpec.java   |  14 +-
 .../apache/calcite/sql/SqlBinaryStringLiteral.java |   5 +-
 .../main/java/org/apache/calcite/sql/SqlCall.java  |   6 +-
 .../apache/calcite/sql/SqlCharStringLiteral.java   |   5 +-
 .../calcite/sql/SqlCollectionTypeNameSpec.java     |   7 +-
 .../org/apache/calcite/sql/SqlDateLiteral.java     |   4 +-
 .../main/java/org/apache/calcite/sql/SqlDdl.java   |   4 +-
 .../org/apache/calcite/sql/SqlDescribeTable.java   |   5 +-
 .../org/apache/calcite/sql/SqlFilterOperator.java  |  10 +-
 .../java/org/apache/calcite/sql/SqlFunction.java   |   5 +-
 .../main/java/org/apache/calcite/sql/SqlHint.java  |   5 +-
 .../java/org/apache/calcite/sql/SqlIdentifier.java |  11 +-
 .../java/org/apache/calcite/sql/SqlInsert.java     |   5 +-
 .../org/apache/calcite/sql/SqlIntervalLiteral.java |  17 +--
 .../apache/calcite/sql/SqlIntervalQualifier.java   |   7 +-
 .../apache/calcite/sql/SqlJdbcDataTypeName.java    |  13 +-
 .../java/org/apache/calcite/sql/SqlLambda.java     |   7 +-
 .../java/org/apache/calcite/sql/SqlLiteral.java    |  12 +-
 .../org/apache/calcite/sql/SqlMatchRecognize.java  |  29 ++--
 .../main/java/org/apache/calcite/sql/SqlNode.java  |   5 +-
 .../java/org/apache/calcite/sql/SqlNodeList.java   |   7 +-
 .../org/apache/calcite/sql/SqlNumericLiteral.java  |  20 +--
 .../java/org/apache/calcite/sql/SqlOperator.java   |   5 +-
 .../main/java/org/apache/calcite/sql/SqlPivot.java |   9 +-
 .../org/apache/calcite/sql/SqlRowTypeNameSpec.java |  11 +-
 .../java/org/apache/calcite/sql/SqlSelect.java     |   4 +-
 .../org/apache/calcite/sql/SqlSelectOperator.java  |   6 +-
 .../java/org/apache/calcite/sql/SqlSetOption.java  |   3 +-
 .../calcite/sql/SqlSetSemanticsTableOperator.java  |  10 +-
 .../java/org/apache/calcite/sql/SqlSnapshot.java   |  11 +-
 .../calcite/sql/SqlSpatialTypeOperatorTable.java   |  18 ++-
 .../java/org/apache/calcite/sql/SqlTableRef.java   |   2 +-
 .../org/apache/calcite/sql/SqlTimeLiteral.java     |   6 +-
 .../org/apache/calcite/sql/SqlTimeTzLiteral.java   |   6 +-
 .../apache/calcite/sql/SqlTimestampLiteral.java    |   6 +-
 .../apache/calcite/sql/SqlTimestampTzLiteral.java  |   6 +-
 .../calcite/sql/SqlTypeConstructorFunction.java    |   2 +-
 .../java/org/apache/calcite/sql/SqlUnpivot.java    |  11 +-
 .../java/org/apache/calcite/sql/SqlUpdate.java     |  16 ++-
 .../main/java/org/apache/calcite/sql/SqlUtil.java  |  72 +++++-----
 .../java/org/apache/calcite/sql/SqlWindow.java     |  35 ++---
 .../calcite/sql/SqlWithinDistinctOperator.java     |   8 +-
 .../apache/calcite/sql/SqlWithinGroupOperator.java |   8 +-
 .../org/apache/calcite/sql/advise/SqlAdvisor.java  |  12 +-
 .../calcite/sql/ddl/SqlCreateForeignSchema.java    |   5 +-
 .../apache/calcite/sql/ddl/SqlCreateFunction.java  |   9 +-
 .../calcite/sql/ddl/SqlCreateMaterializedView.java |   7 +-
 .../apache/calcite/sql/ddl/SqlCreateSchema.java    |   5 +-
 .../org/apache/calcite/sql/ddl/SqlCreateTable.java |   5 +-
 .../org/apache/calcite/sql/ddl/SqlCreateType.java  |   5 +-
 .../org/apache/calcite/sql/ddl/SqlCreateView.java  |   7 +-
 .../calcite/sql/dialect/BigQuerySqlDialect.java    |   3 +-
 .../calcite/sql/dialect/FireboltSqlDialect.java    |   4 +-
 .../calcite/sql/dialect/PrestoSqlDialect.java      |   9 +-
 .../calcite/sql/fun/SqlAbstractGroupFunction.java  |   5 +-
 .../calcite/sql/fun/SqlBasicAggFunction.java       |   3 +-
 .../org/apache/calcite/sql/fun/SqlDotOperator.java |   3 +-
 .../apache/calcite/sql/fun/SqlExtractFunction.java |  10 +-
 .../sql/fun/SqlJsonArrayAggAggFunction.java        |   4 +-
 .../sql/fun/SqlJsonObjectAggAggFunction.java       |   4 +-
 .../calcite/sql/fun/SqlJsonQueryFunction.java      |   7 +-
 .../calcite/sql/fun/SqlJsonValueFunction.java      |   4 +-
 .../calcite/sql/fun/SqlLiteralChainOperator.java   |   2 +-
 .../calcite/sql/fun/SqlMapValueConstructor.java    |   2 +-
 .../sql/fun/SqlMultisetValueConstructor.java       |   2 +-
 .../calcite/sql/fun/SqlQuantifyOperator.java       |  18 ++-
 .../apache/calcite/sql/fun/SqlRollupOperator.java  |   2 +-
 .../calcite/sql/fun/SqlSpatialTypeFunctions.java   |   2 +-
 .../apache/calcite/sql/parser/SqlParserPos.java    |   4 +-
 .../apache/calcite/sql/pretty/SqlPrettyWriter.java |  36 +++--
 .../apache/calcite/sql/type/AbstractSqlType.java   |   7 +-
 .../org/apache/calcite/sql/type/BasicSqlType.java  |   5 +-
 .../sql/type/ComparableOperandTypeChecker.java     |   4 +-
 .../sql/type/ExplicitOperandTypeChecker.java       |   3 +-
 .../sql/type/ExplicitReturnTypeInference.java      |   5 +-
 .../apache/calcite/sql/type/FunctionSqlType.java   |   6 +-
 .../apache/calcite/sql/type/IntervalSqlType.java   |  11 +-
 .../org/apache/calcite/sql/type/MapSqlType.java    |   8 +-
 .../apache/calcite/sql/type/MultisetSqlType.java   |   7 +-
 .../calcite/sql/type/OperandMetadataImpl.java      |   6 +-
 .../org/apache/calcite/sql/type/OperandTypes.java  |   2 +-
 .../org/apache/calcite/sql/type/ReturnTypes.java   |  44 +++---
 .../calcite/sql/type/SqlTypeCoercionRule.java      |   5 +-
 .../calcite/sql/type/SqlTypeMappingRule.java       |   7 +-
 .../calcite/sql/type/SqlTypeTransformCascade.java  |   6 +-
 .../org/apache/calcite/sql/type/SqlTypeUtil.java   |  12 +-
 .../sql/type/TableFunctionReturnTypeInference.java |   8 +-
 .../java/org/apache/calcite/sql/util/IdPair.java   |   7 +-
 .../org/apache/calcite/sql/util/SqlBuilder.java    |  18 +--
 .../org/apache/calcite/sql/util/SqlShuttle.java    |   2 +-
 .../org/apache/calcite/sql/util/SqlString.java     |  12 +-
 .../apache/calcite/sql/validate/AggVisitor.java    |   7 +-
 .../apache/calcite/sql/validate/CollectScope.java  |  16 +--
 .../calcite/sql/validate/DelegatingScope.java      |   8 +-
 .../calcite/sql/validate/FieldNamespace.java       |   3 +-
 .../calcite/sql/validate/IdentifierNamespace.java  |   4 +-
 .../apache/calcite/sql/validate/SelectScope.java   |   4 +-
 .../calcite/sql/validate/SqlIdentifierMoniker.java |   5 +-
 .../calcite/sql/validate/SqlMonikerImpl.java       |   4 +-
 .../calcite/sql/validate/SqlValidatorImpl.java     | 127 +++++++++--------
 .../calcite/sql/validate/SqlValidatorUtil.java     |  18 +--
 .../calcite/sql/validate/TableNamespace.java       |   4 +-
 .../apache/calcite/sql/validate/TableScope.java    |   6 +-
 .../calcite/sql/validate/UnnestNamespace.java      |   7 +-
 .../validate/implicit/AbstractTypeCoercion.java    |   4 +-
 .../org/apache/calcite/sql2rel/AggConverter.java   |   2 +-
 .../apache/calcite/sql2rel/RelDecorrelator.java    |  45 +++---
 .../apache/calcite/sql2rel/RelFieldTrimmer.java    |   7 +-
 .../sql2rel/RelStructuredTypeFlattener.java        |  19 +--
 .../apache/calcite/sql2rel/SqlToRelConverter.java  | 133 +++++++++---------
 .../calcite/sql2rel/StandardConvertletTable.java   |  31 +++--
 .../apache/calcite/sql2rel/SubQueryConverter.java  |   4 +-
 .../java/org/apache/calcite/tools/Frameworks.java  |  27 ++--
 .../main/java/org/apache/calcite/tools/Hoist.java  |   9 +-
 .../org/apache/calcite/tools/PigRelBuilder.java    |  12 +-
 .../java/org/apache/calcite/tools/Programs.java    |   5 +-
 .../java/org/apache/calcite/tools/RelBuilder.java  |  24 ++--
 .../java/org/apache/calcite/util/Benchmark.java    |  10 +-
 .../main/java/org/apache/calcite/util/BitSets.java |   2 +-
 .../java/org/apache/calcite/util/BitString.java    |   5 +-
 .../java/org/apache/calcite/util/CancelFlag.java   |   5 +-
 .../java/org/apache/calcite/util/DateString.java   |   8 +-
 .../org/apache/calcite/util/EquivalenceSet.java    |   4 +-
 .../java/org/apache/calcite/util/Filterator.java   |   4 +-
 .../apache/calcite/util/ImmutableNullableSet.java  |   5 +-
 .../apache/calcite/util/IntegerIntervalSet.java    |   8 +-
 .../java/org/apache/calcite/util/NlsString.java    |   8 +-
 .../main/java/org/apache/calcite/util/Pair.java    |  20 +--
 .../apache/calcite/util/PartiallyOrderedSet.java   |   2 +-
 .../java/org/apache/calcite/util/ReflectUtil.java  |  44 +++---
 .../apache/calcite/util/SerializableCharset.java   |   3 +-
 .../apache/calcite/util/SourceStringReader.java    |   7 +-
 .../main/java/org/apache/calcite/util/Sources.java |  11 +-
 .../java/org/apache/calcite/util/StackWriter.java  |   2 +-
 .../java/org/apache/calcite/util/TimeString.java   |   7 +-
 .../apache/calcite/util/UnmodifiableArrayList.java |   5 +-
 .../main/java/org/apache/calcite/util/Util.java    |  31 ++---
 .../util/format/postgresql/FormatPattern.java      |   2 +-
 .../format/postgresql/NumberFormatPattern.java     |   4 +-
 .../postgresql/TimeZoneHoursFormatPattern.java     |   4 +-
 .../postgresql/TimeZoneMinutesFormatPattern.java   |   4 +-
 .../postgresql/YearWithCommasFormatPattern.java    |   4 +-
 .../org/apache/calcite/util/graph/DefaultEdge.java |   6 +-
 .../apache/calcite/util/javac/JaninoCompiler.java  |   2 +-
 .../calcite/util/javac/JavaCompilerArgs.java       |   4 +-
 .../apache/calcite/util/trace/CalciteLogger.java   |   5 +-
 .../calcite/plan/visualizer/viz-template.html      |   2 +-
 .../calcite/runtime/CalciteResource.properties     |   1 -
 .../CustomMaterializedViewRecognitionRuleTest.java |  29 ++--
 .../plan/volcano/CollationConversionTest.java      |   6 +-
 .../apache/calcite/plan/volcano/PlannerTests.java  |   2 +-
 .../calcite/plan/volcano/VolcanoPlannerTest.java   |  10 +-
 .../prepare/LookupOperatorOverloadsTest.java       |  20 +--
 .../org/apache/calcite/profile/ProfilerTest.java   |  13 +-
 .../calcite/rel/rules/EnumerableLimitRuleTest.java |   2 +-
 .../calcite/rel/rules/SortRemoveRuleTest.java      |   4 +-
 .../org/apache/calcite/rex/RexExecutorTest.java    |  29 ++--
 .../org/apache/calcite/rex/RexProgramTest.java     |   7 +-
 .../org/apache/calcite/rex/RexProgramTestBase.java |   8 +-
 .../apache/calcite/runtime/EnumerablesTest.java    |   9 +-
 .../ExtensionSqlCreateTable.java                   |   4 +-
 .../calcite/sql/validate/LexCaseSensitiveTest.java |   3 +-
 .../apache/calcite/sql/validate/LexEscapeTest.java |   3 +-
 .../calcite/sql2rel/RelDecorrelatorTest.java       |   6 +-
 .../apache/calcite/test/CollectionTypeTest.java    |   2 +-
 .../apache/calcite/test/ExceptionMessageTest.java  | 149 ++++++++++----------
 .../org/apache/calcite/test/HepPlannerTest.java    |   9 +-
 .../org/apache/calcite/test/InterpreterTest.java   |  47 ++++---
 .../apache/calcite/test/JdbcFrontLinqBackTest.java |   2 +-
 .../java/org/apache/calcite/test/JdbcTest.java     | 149 +++++++++++---------
 .../calcite/test/LargeGeneratedJoinTest.java       |   6 +-
 .../java/org/apache/calcite/test/LatticeTest.java  |  16 ++-
 .../apache/calcite/test/LinqFrontJdbcBackTest.java |   7 +-
 .../java/org/apache/calcite/test/LintTest.java     |   4 +-
 .../apache/calcite/test/MaterializationTest.java   |   2 +-
 .../calcite/test/MaterializedViewTester.java       |   6 +-
 .../java/org/apache/calcite/test/ModelTest.java    |  31 +++--
 .../calcite/test/MultiJdbcSchemaJoinTest.java      |   2 +-
 .../org/apache/calcite/test/RelBuilderTest.java    |  70 +++++-----
 .../org/apache/calcite/test/RelMetadataTest.java   |  24 +++-
 .../org/apache/calcite/test/RelOptRulesTest.java   |   2 +-
 .../calcite/test/RuleMatchVisualizerTest.java      |   4 +-
 .../apache/calcite/test/SqlAdvisorJdbcTest.java    |  24 ++--
 .../apache/calcite/test/SqlHintsConverterTest.java |  28 ++--
 .../org/apache/calcite/test/SqlValidatorTest.java  |   3 +-
 .../org/apache/calcite/test/TimeFrameTest.java     |   6 +-
 .../concurrent/ConcurrentTestCommandExecutor.java  |  24 ++--
 .../concurrent/ConcurrentTestCommandGenerator.java |  45 +++---
 .../concurrent/ConcurrentTestCommandScript.java    | 140 ++++++++++---------
 .../concurrent/ConcurrentTestPluginCommand.java    |   7 +-
 .../ConcurrentTestTimedCommandGenerator.java       |   8 +-
 .../calcite/test/concurrent/SamplePlugin.java      |   3 +-
 .../calcite/util/PartiallyOrderedSetTest.java      |   7 +-
 .../adapter/druid/BinaryOperatorConversion.java    |   6 +-
 .../adapter/druid/CeilOperatorConversion.java      |   5 +-
 .../adapter/druid/DefaultDimensionSpec.java        |  14 +-
 .../adapter/druid/DirectOperatorConversion.java    |   6 +-
 .../calcite/adapter/druid/DruidConnectionImpl.java |  14 +-
 .../calcite/adapter/druid/DruidDateTimeUtils.java  |  15 +-
 .../calcite/adapter/druid/DruidExpressions.java    |  20 +--
 .../calcite/adapter/druid/DruidJsonFilter.java     |  15 +-
 .../apache/calcite/adapter/druid/DruidQuery.java   | 119 +++++++++-------
 .../apache/calcite/adapter/druid/DruidRules.java   |  17 ++-
 .../apache/calcite/adapter/druid/DruidSchema.java  |  11 +-
 .../calcite/adapter/druid/DruidSchemaFactory.java  |   5 +-
 .../adapter/druid/DruidSqlCastConverter.java       |   9 +-
 .../apache/calcite/adapter/druid/DruidTable.java   |  42 +++---
 .../calcite/adapter/druid/DruidTableFactory.java   |   4 +-
 .../apache/calcite/adapter/druid/DruidType.java    |   8 +-
 .../adapter/druid/ExtractOperatorConversion.java   |   4 +-
 .../adapter/druid/ExtractionDimensionSpec.java     |   8 +-
 .../calcite/adapter/druid/Granularities.java       |   9 +-
 .../adapter/druid/NaryOperatorConverter.java       |   8 +-
 .../druid/UnaryPrefixOperatorConversion.java       |   6 +-
 .../druid/UnarySuffixOperatorConversion.java       |   6 +-
 .../calcite/adapter/druid/VirtualColumn.java       |   7 +-
 .../elasticsearch/ElasticsearchAggregate.java      |   5 +-
 .../elasticsearch/ElasticsearchEnumerators.java    |   5 +-
 .../adapter/elasticsearch/ElasticsearchFilter.java |   8 +-
 .../adapter/elasticsearch/ElasticsearchJson.java   |  36 ++---
 .../elasticsearch/ElasticsearchMapping.java        |   9 +-
 .../elasticsearch/ElasticsearchProject.java        |  11 +-
 .../adapter/elasticsearch/ElasticsearchRel.java    |  19 +--
 .../adapter/elasticsearch/ElasticsearchRules.java  |   6 +-
 .../adapter/elasticsearch/ElasticsearchSchema.java |  15 +-
 .../elasticsearch/ElasticsearchSchemaFactory.java  |   5 +-
 .../elasticsearch/ElasticsearchSearchResult.java   |  13 +-
 .../adapter/elasticsearch/ElasticsearchSort.java   |  26 ++--
 .../adapter/elasticsearch/ElasticsearchTable.java  |   9 +-
 .../elasticsearch/ElasticsearchTableScan.java      |  13 +-
 .../ElasticsearchToEnumerableConverter.java        |  10 +-
 .../elasticsearch/ElasticsearchTransport.java      |  25 ++--
 .../elasticsearch/ElasticsearchVersion.java        |   8 +-
 .../adapter/elasticsearch/PredicateAnalyzer.java   |   5 +-
 .../adapter/elasticsearch/QueryBuilders.java       |  41 +++---
 .../calcite/adapter/elasticsearch/Scrolling.java   |   7 +-
 .../elasticsearch/ElasticSearchAdapterTest.java    |   7 +-
 .../elasticsearch/EmbeddedElasticsearchNode.java   |   4 +-
 .../elasticsearch/EmbeddedElasticsearchPolicy.java |  21 +--
 .../calcite/adapter/elasticsearch/MatchTest.java   |   9 +-
 .../apache/calcite/test/ElasticsearchChecker.java  |   7 +-
 .../calcite/adapter/csv/CsvFilterableTable.java    |   3 +-
 .../adapter/csv/CsvProjectTableScanRule.java       |   5 +-
 .../calcite/adapter/csv/CsvScannableTable.java     |   2 +-
 .../org/apache/calcite/adapter/csv/CsvSchema.java  |   6 +-
 .../adapter/csv/CsvStreamScannableTable.java       |   3 +-
 .../apache/calcite/adapter/csv/CsvTableScan.java   |  12 +-
 .../calcite/adapter/csv/CsvTranslatableTable.java  |   4 +-
 .../test/java/org/apache/calcite/test/CsvTest.java |  65 +++++----
 .../apache/calcite/test/ExampleFunctionTest.java   |  14 +-
 .../apache/calcite/adapter/file/CsvEnumerator.java |  30 ++--
 .../calcite/adapter/file/CsvStreamReader.java      |  19 ++-
 .../org/apache/calcite/adapter/file/CsvTable.java  |  10 +-
 .../apache/calcite/adapter/file/CsvTableScan.java  |  14 +-
 .../calcite/adapter/file/CsvTranslatableTable.java |   4 +-
 .../calcite/adapter/file/FileEnumerator.java       |   3 +-
 .../apache/calcite/adapter/file/FileFieldType.java |  10 +-
 .../apache/calcite/adapter/file/FileReader.java    |  33 +++--
 .../calcite/adapter/file/FileReaderException.java  |   2 +-
 .../calcite/adapter/file/FileRowConverter.java     | 120 +++++++---------
 .../apache/calcite/adapter/file/FileSchema.java    |  23 ++-
 .../org/apache/calcite/adapter/file/FileTable.java |  15 +-
 .../apache/calcite/adapter/file/FileTableScan.java |   9 +-
 .../calcite/adapter/file/FileAdapterTest.java      |   2 +-
 .../calcite/adapter/file/FileAdapterTests.java     |  12 +-
 .../calcite/adapter/file/FileReaderTest.java       |   8 +-
 .../calcite/adapter/geode/rel/GeodeAggregate.java  |   5 +-
 .../calcite/adapter/geode/rel/GeodeEnumerator.java |  12 +-
 .../calcite/adapter/geode/rel/GeodeFilter.java     |  45 +++---
 .../calcite/adapter/geode/rel/GeodeProject.java    |   5 +-
 .../calcite/adapter/geode/rel/GeodeRules.java      |   3 +-
 .../calcite/adapter/geode/rel/GeodeSchema.java     |   7 +-
 .../calcite/adapter/geode/rel/GeodeSort.java       |  10 +-
 .../calcite/adapter/geode/rel/GeodeTable.java      |  18 ++-
 .../calcite/adapter/geode/rel/GeodeTableScan.java  |  16 ++-
 .../geode/rel/GeodeToEnumerableConverter.java      |   5 +-
 .../geode/simple/GeodeSimpleEnumerator.java        |  11 +-
 .../geode/simple/GeodeSimpleScannableTable.java    |   4 +-
 .../adapter/geode/simple/GeodeSimpleSchema.java    |  23 +--
 .../calcite/adapter/geode/util/GeodeUtils.java     |  14 +-
 .../adapter/geode/rel/GeodeEmbeddedPolicy.java     |   8 +-
 .../calcite/adapter/geode/rel/JsonLoader.java      |   9 +-
 .../calcite/adapter/innodb/IndexCondition.java     |  17 ++-
 .../calcite/adapter/innodb/InnodbEnumerator.java   |  18 +--
 .../calcite/adapter/innodb/InnodbFilter.java       |   9 +-
 .../adapter/innodb/InnodbFilterTranslator.java     |   9 +-
 .../calcite/adapter/innodb/InnodbProject.java      |   5 +-
 .../apache/calcite/adapter/innodb/InnodbRules.java |  10 +-
 .../apache/calcite/adapter/innodb/InnodbSort.java  |   4 +-
 .../apache/calcite/adapter/innodb/InnodbTable.java |  12 +-
 .../calcite/adapter/innodb/InnodbTableScan.java    |  17 ++-
 .../innodb/InnodbToEnumerableConverter.java        |  10 +-
 .../adapter/innodb/InnodbAdapterDataTypesTest.java |   7 +-
 .../calcite/adapter/innodb/InnodbAdapterTest.java  |  37 +++--
 .../calcite/adapter/kafka/KafkaAdapterTest.java    |   8 +-
 .../apache/calcite/linq4j/DefaultEnumerable.java   |   2 +-
 .../apache/calcite/linq4j/EnumerableDefaults.java  |  47 +++----
 .../apache/calcite/linq4j/ExtendedEnumerable.java  |   2 +-
 .../org/apache/calcite/linq4j/GroupingImpl.java    |   7 +-
 .../java/org/apache/calcite/linq4j/Linq4j.java     |  19 +--
 .../java/org/apache/calcite/linq4j/LookupImpl.java |   2 +-
 .../apache/calcite/linq4j/tree/AbstractNode.java   |  17 +--
 .../linq4j/tree/ArrayLengthRecordField.java        |  20 +--
 .../calcite/linq4j/tree/BinaryExpression.java      |   6 +-
 .../apache/calcite/linq4j/tree/BlockBuilder.java   |   6 +-
 .../apache/calcite/linq4j/tree/BlockStatement.java |   5 +-
 .../calcite/linq4j/tree/ClassDeclaration.java      |  26 +---
 .../calcite/linq4j/tree/ConditionalExpression.java |   5 +-
 .../calcite/linq4j/tree/ConditionalStatement.java  |  12 +-
 .../linq4j/tree/ConstructorDeclaration.java        |  30 ++--
 .../calcite/linq4j/tree/DeclarationStatement.java  |  21 +--
 .../org/apache/calcite/linq4j/tree/Expression.java |   2 -
 .../apache/calcite/linq4j/tree/Expressions.java    |  23 +--
 .../calcite/linq4j/tree/FieldDeclaration.java      |  21 +--
 .../calcite/linq4j/tree/ForEachStatement.java      |   8 +-
 .../apache/calcite/linq4j/tree/ForStatement.java   |  36 ++---
 .../calcite/linq4j/tree/FunctionExpression.java    |  30 ++--
 .../apache/calcite/linq4j/tree/GotoStatement.java  |  30 ++--
 .../calcite/linq4j/tree/IndexExpression.java       |  12 +-
 .../calcite/linq4j/tree/MemberExpression.java      |  11 +-
 .../calcite/linq4j/tree/MethodCallExpression.java  |  36 +++--
 .../calcite/linq4j/tree/MethodDeclaration.java     |  37 ++---
 .../calcite/linq4j/tree/ParameterExpression.java   |  14 +-
 .../calcite/linq4j/tree/ReflectedPseudoField.java  |   5 +-
 .../calcite/linq4j/tree/TernaryExpression.java     |  11 +-
 .../apache/calcite/linq4j/tree/TryStatement.java   |   6 +-
 .../calcite/linq4j/tree/TypeBinaryExpression.java  |  16 +--
 .../java/org/apache/calcite/linq4j/tree/Types.java | 112 ++++++---------
 .../calcite/linq4j/tree/UnaryExpression.java       |  12 +-
 .../apache/calcite/linq4j/tree/WhileStatement.java |  19 +--
 .../calcite/linq4j/test/BlockBuilderTest.java      |   3 +-
 .../apache/calcite/linq4j/test/ExpressionTest.java |  86 +++++++-----
 .../calcite/linq4j/test/JoinPreserveOrderTest.java |  26 ++--
 .../apache/calcite/linq4j/test/LimitSortTest.java  |  21 ++-
 .../org/apache/calcite/linq4j/test/Linq4jTest.java |  35 +++--
 .../calcite/adapter/mongodb/MongoAggregate.java    |   8 +-
 .../calcite/adapter/mongodb/MongoEnumerator.java   |   6 +-
 .../apache/calcite/adapter/mongodb/MongoRel.java   |  10 +-
 .../calcite/adapter/mongodb/MongoSchema.java       |   5 +-
 .../calcite/adapter/mongodb/MongoTableScan.java    |  18 ++-
 .../calcite/adapter/mongodb/MongoAdapterTest.java  |  23 ++-
 .../adapter/mongodb/MongoDatabasePolicy.java       |   9 +-
 .../apache/calcite/adapter/pig/PigTableScan.java   |   5 +-
 .../org/apache/calcite/test/AbstractPigTest.java   |   8 +-
 .../org/apache/calcite/test/PigAdapterTest.java    |   4 +-
 .../calcite/test/PigRelBuilderStyleTest.java       |   6 +-
 .../main/java/org/apache/calcite/piglet/Ast.java   |  23 +--
 .../calcite/piglet/DynamicTupleRecordType.java     |   4 +-
 .../org/apache/calcite/piglet/PigRelBuilder.java   |  10 +-
 .../org/apache/calcite/piglet/PigRelExVisitor.java |  49 ++++---
 .../calcite/piglet/PigRelOpInnerVisitor.java       |   9 +-
 .../org/apache/calcite/piglet/PigRelOpVisitor.java |   8 +-
 .../calcite/adapter/os/FilesTableFunction.java     |   2 +-
 .../adapter/os/GitCommitsTableFunction.java        |  10 +-
 .../org/apache/calcite/adapter/os/Processes.java   |   6 +-
 .../apache/calcite/adapter/os/PsTableFunction.java |  19 +--
 .../org/apache/calcite/adapter/os/SqlShell.java    |   9 +-
 .../calcite/adapter/os/VmstatTableFunction.java    |   6 +-
 .../apache/calcite/adapter/tpcds/TpcdsSchema.java  |   4 +-
 .../apache/calcite/adapter/tpch/TpchSchema.java    |  11 +-
 .../calcite/chinook/CalciteConnectionProvider.java |   3 +
 .../java/org/apache/calcite/slt/SqlLogicTests.java |   8 +-
 .../calcite/adapter/redis/RedisDataProcess.java    |  47 ++++---
 .../calcite/adapter/redis/RedisEnumerator.java     |   6 +-
 .../calcite/adapter/redis/RedisJedisManager.java   |  24 ++--
 .../apache/calcite/adapter/redis/RedisSchema.java  |  21 +--
 .../calcite/adapter/redis/RedisSchemaFactory.java  |   4 +-
 .../adapter/redis/RedisAdapterCaseBase.java        |   2 +-
 server/build.gradle.kts                            |   3 +
 .../calcite/server/AbstractModifiableTable.java    |   8 +-
 .../apache/calcite/server/MutableArrayTable.java   |  12 +-
 .../apache/calcite/server/ServerDdlExecutor.java   | 155 ++++++++++++---------
 site/_layouts/default.html                         |   1 -
 .../adapter/spark/EnumerableToSparkConverter.java  |   5 +-
 .../apache/calcite/adapter/spark/HttpServer.java   |   3 +-
 .../adapter/spark/JdbcToSparkConverter.java        |   7 +-
 .../calcite/adapter/splunk/SplunkDriver.java       |  20 +--
 .../apache/calcite/adapter/splunk/SplunkQuery.java |  23 +--
 .../apache/calcite/adapter/splunk/SplunkTable.java |  11 +-
 .../calcite/adapter/splunk/SplunkTableScan.java    |   9 +-
 .../adapter/splunk/search/SplunkConnection.java    |   6 +-
 .../splunk/search/SplunkConnectionImpl.java        |  49 ++++---
 .../config/checkerframework/jdbc/Connection.astub  |  16 +--
 .../apache/calcite/sql/parser/SqlParserTest.java   |   8 +-
 .../apache/calcite/sql/test/AbstractSqlTester.java |  20 +--
 .../apache/calcite/sql/test/ResultCheckers.java    |   8 +-
 .../org/apache/calcite/sql/test/SqlTester.java     |   4 +-
 .../java/org/apache/calcite/sql/test/SqlTests.java |  14 +-
 .../calcite/test/AbstractModifiableTable.java      |   8 +-
 .../org/apache/calcite/test/CalciteAssert.java     | 108 +++++++-------
 .../org/apache/calcite/test/ConnectionSpec.java    |   4 +-
 .../org/apache/calcite/test/DiffRepository.java    |  66 +++++----
 .../java/org/apache/calcite/test/DiffTestCase.java |  57 +++++---
 .../org/apache/calcite/test/MockDdlExecutor.java   |   3 +-
 .../org/apache/calcite/test/MockRelOptPlanner.java |   4 +-
 .../org/apache/calcite/test/SqlOperatorTest.java   |   7 +-
 .../calcite/test/catalog/MockCatalogReader.java    |  60 +++++---
 .../test/schemata/bookstore/BookstoreSchema.java   |   7 +-
 .../test/schemata/catchall/CatchallSchema.java     |  62 +++++----
 .../test/schemata/foodmart/FoodmartSchema.java     |   4 +-
 .../calcite/test/schemata/hr/Department.java       |   6 +-
 .../calcite/test/schemata/hr/DepartmentPlus.java   |   4 +-
 .../apache/calcite/test/schemata/hr/Employee.java  |   6 +-
 .../org/apache/calcite/test/schemata/hr/Event.java |   6 +-
 .../calcite/test/schemata/hr/NullableTest.java     |   9 +-
 .../calcite/test/schemata/tpch/TpchSchema.java     |   4 +-
 .../main/java/org/apache/calcite/util/Smalls.java  |  14 +-
 .../java/org/apache/calcite/util/TestUtil.java     |   5 +-
 .../apache/calcite/benchmarks/ParserBenchmark.java |   2 +-
 .../benchmarks/RelNodeConversionBenchmark.java     |   2 +-
 .../apache/calcite/benchmarks/StatementTest.java   |  10 +-
 606 files changed, 4258 insertions(+), 3718 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 56a9276cbd..35613b0b26 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -377,9 +377,9 @@ jobs:
         with:
           job-id: checkerframework-jdk11
           remote-build-cache-proxy-enabled: false
-          arguments: --scan --no-parallel --no-daemon -PenableCheckerframework :linq4j:classes :core:classes
+          arguments: --scan --no-parallel --no-daemon -PenableCheckerframework :linq4j:classes :core:classes :server:classes
 
-  linux-checkerframework-guava29:
+  linux-checkerframework-oldest-guava:
     name: 'CheckerFramework (JDK 11), oldest Guava'
     runs-on: ubuntu-latest
     env:
@@ -398,7 +398,7 @@ jobs:
         with:
           job-id: checkerframework-jdk11
           remote-build-cache-proxy-enabled: false
-          arguments: --scan --no-parallel --no-daemon -Pguava.version=${{ env.GUAVA }} -PenableCheckerframework :linq4j:classes :core:classes
+          arguments: --scan --no-parallel --no-daemon -Pguava.version=${{ env.GUAVA }} -PenableCheckerframework :linq4j:classes :core:classes :server:classes
 
   linux-slow:
     # Run slow tests when the commit is on main or it is requested explicitly by adding an
diff --git a/arrow/src/main/java/org/apache/calcite/adapter/arrow/ArrowFilterEnumerator.java b/arrow/src/main/java/org/apache/calcite/adapter/arrow/ArrowFilterEnumerator.java
index c52a542905..e54a8c6ed0 100644
--- a/arrow/src/main/java/org/apache/calcite/adapter/arrow/ArrowFilterEnumerator.java
+++ b/arrow/src/main/java/org/apache/calcite/adapter/arrow/ArrowFilterEnumerator.java
@@ -29,16 +29,20 @@ import org.apache.arrow.memory.RootAllocator;
 import org.apache.arrow.vector.ipc.ArrowFileReader;
 import org.apache.arrow.vector.ipc.message.ArrowRecordBatch;
 
+import org.checkerframework.checker.nullness.qual.Nullable;
+
 import java.io.IOException;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Enumerator that reads from a filtered collection of Arrow value-vectors.
  */
 class ArrowFilterEnumerator extends AbstractArrowEnumerator {
   private final BufferAllocator allocator;
   private final Filter filter;
-  private ArrowBuf buf;
-  private SelectionVector selectionVector;
+  private @Nullable ArrowBuf buf;
+  private @Nullable SelectionVector selectionVector;
   private int selectionVectorIndex;
 
   ArrowFilterEnumerator(ArrowFileReader arrowFileReader, ImmutableIntList fields, Filter filter) {
@@ -71,7 +75,7 @@ class ArrowFilterEnumerator extends AbstractArrowEnumerator {
           selectionVectorIndex = 0;
           this.valueVectors.clear();
           loadNextArrowBatch();
-          assert selectionVector != null;
+          requireNonNull(selectionVector, "selectionVector");
           if (selectionVectorIndex >= selectionVector.getRecordCount()) {
             // the "filtered" batch is empty, but there may be more batches to fetch
             continue;
diff --git a/arrow/src/main/java/org/apache/calcite/adapter/arrow/ArrowTable.java b/arrow/src/main/java/org/apache/calcite/adapter/arrow/ArrowTable.java
index 9f723d07f6..ec9fe405e8 100644
--- a/arrow/src/main/java/org/apache/calcite/adapter/arrow/ArrowTable.java
+++ b/arrow/src/main/java/org/apache/calcite/adapter/arrow/ArrowTable.java
@@ -55,6 +55,10 @@ import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
 
+import static java.lang.Double.parseDouble;
+import static java.lang.Float.parseFloat;
+import static java.lang.Integer.parseInt;
+import static java.lang.Long.parseLong;
 import static java.util.Objects.requireNonNull;
 
 /**
@@ -183,13 +187,13 @@ public class ArrowTable extends AbstractTable
   private static TreeNode makeLiteralNode(String literal, String type) {
     switch (type) {
     case "integer":
-      return TreeBuilder.makeLiteral(Integer.parseInt(literal));
+      return TreeBuilder.makeLiteral(parseInt(literal));
     case "long":
-      return TreeBuilder.makeLiteral(Long.parseLong(literal));
+      return TreeBuilder.makeLiteral(parseLong(literal));
     case "float":
-      return TreeBuilder.makeLiteral(Float.parseFloat(literal));
+      return TreeBuilder.makeLiteral(parseFloat(literal));
     case "double":
-      return TreeBuilder.makeLiteral(Double.parseDouble(literal));
+      return TreeBuilder.makeLiteral(parseDouble(literal));
     case "string":
       return TreeBuilder.makeStringLiteral(literal.substring(1, literal.length() - 1));
     default:
diff --git a/arrow/src/test/java/org/apache/calcite/adapter/arrow/ArrowAdapterTest.java b/arrow/src/test/java/org/apache/calcite/adapter/arrow/ArrowAdapterTest.java
index 3158d0011a..d48576a117 100644
--- a/arrow/src/test/java/org/apache/calcite/adapter/arrow/ArrowAdapterTest.java
+++ b/arrow/src/test/java/org/apache/calcite/adapter/arrow/ArrowAdapterTest.java
@@ -43,10 +43,11 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.sql.SQLException;
 import java.util.Map;
-import java.util.Objects;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Tests for the Apache Arrow adapter.
  */
@@ -57,9 +58,11 @@ class ArrowAdapterTest {
   private static File arrowDataDirectory;
 
   @BeforeAll
-  static void initializeArrowState(@TempDir Path sharedTempDir) throws IOException, SQLException {
+  static void initializeArrowState(@TempDir Path sharedTempDir)
+      throws IOException, SQLException {
     URL modelUrl =
-        Objects.requireNonNull(ArrowAdapterTest.class.getResource("/arrow-model.json"), "url");
+        requireNonNull(
+            ArrowAdapterTest.class.getResource("/arrow-model.json"), "url");
     Path sourceModelFilePath = Sources.of(modelUrl).file().toPath();
     Path modelFileTarget = sharedTempDir.resolve("arrow-model.json");
     Files.copy(sourceModelFilePath, modelFileTarget);
diff --git a/babel/src/test/java/org/apache/calcite/test/BabelQuidemTest.java b/babel/src/test/java/org/apache/calcite/test/BabelQuidemTest.java
index dff24ba13a..e368afbd07 100644
--- a/babel/src/test/java/org/apache/calcite/test/BabelQuidemTest.java
+++ b/babel/src/test/java/org/apache/calcite/test/BabelQuidemTest.java
@@ -40,6 +40,7 @@ import net.hydromatic.quidem.Command;
 import net.hydromatic.quidem.CommandHandler;
 import net.hydromatic.quidem.Quidem;
 
+import org.checkerframework.checker.nullness.qual.Nullable;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 
@@ -167,13 +168,11 @@ class BabelQuidemTest extends QuidemTest {
   static class ExplainValidatedCommand extends AbstractCommand {
     private final ImmutableList<String> lines;
     private final ImmutableList<String> content;
-    private final Set<String> productSet;
 
     ExplainValidatedCommand(List<String> lines, List<String> content,
-        Set<String> productSet) {
+        Set<String> unusedProductSet) {
       this.lines = ImmutableList.copyOf(lines);
       this.content = ImmutableList.copyOf(content);
-      this.productSet = ImmutableSet.copyOf(productSet);
     }
 
     @Override public void execute(Context x, boolean execute) throws Exception {
@@ -214,7 +213,7 @@ class BabelQuidemTest extends QuidemTest {
   /** Command handler that adds a "!explain-validated-on dialect..." command
    * (see {@link ExplainValidatedCommand}). */
   private static class BabelCommandHandler implements CommandHandler {
-    @Override public Command parseCommand(List<String> lines,
+    @Override public @Nullable Command parseCommand(List<String> lines,
         List<String> content, String line) {
       final String prefix = "explain-validated-on";
       if (line.startsWith(prefix)) {
diff --git a/build.gradle.kts b/build.gradle.kts
index 6f6d6c2981..85e9d448e7 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -666,6 +666,14 @@ allprojects {
                     replace("hamcrest: sameInstance", "org.hamcrest.core.IsSame.sameInstance", "org.hamcrest.CoreMatchers.sameInstance")
                     replace("hamcrest: startsWith", "org.hamcrest.core.StringStartsWith.startsWith", "org.hamcrest.CoreMatchers.startsWith")
                     replaceRegex("hamcrest: size", "\\.size\\(\\), (is|equalTo)\\(", ", hasSize\\(")
+                    replaceRegex("use static import: parseBoolean", "Boolean\\.(parseBoolean\\()", "$1")
+                    replaceRegex("use static import: parseByte", "Byte\\.(parseByte\\()", "$1")
+                    replaceRegex("use static import: parseDouble", "Double\\.(parseDouble\\()", "$1")
+                    replaceRegex("use static import: parseFloat", "Float\\.(parseFloat\\()", "$1")
+                    replaceRegex("use static import: parseInt", "Integer\\.(parseInt\\()", "$1")
+                    replaceRegex("use static import: parseLong", "Long\\.(parseLong\\()", "$1")
+                    replaceRegex("use static import: parseLong", "Short\\.(parseShort\\()", "$1")
+                    replaceRegex("use static import: requireNonNull", "Objects\\.(requireNonNull\\()", "$1")
                     replaceRegex("use static import: toImmutableList", "ImmutableList\\.(toImmutableList\\(\\))", "$1")
                     replaceRegex("use static import: checkArgument", "Preconditions\\.(checkArgument\\()", "$1")
                     replaceRegex("use static import: checkArgument", "Preconditions\\.(checkState\\()", "$1")
@@ -778,6 +786,9 @@ allprojects {
                 if (project.path == ":core") {
                     extraJavacArgs.add("-AskipDefs=^org\\.apache\\.calcite\\.sql\\.parser\\.impl\\.")
                 }
+                if (project.path == ":server") {
+                    extraJavacArgs.add("-AskipDefs=^org\\.apache\\.calcite\\.sql\\.parser\\.ddl\\.")
+                }
             }
         }
 
diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraEnumerator.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraEnumerator.java
index 817c7c7126..7d5d0baa04 100644
--- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraEnumerator.java
+++ b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraEnumerator.java
@@ -42,6 +42,8 @@ import java.util.List;
 import java.util.Objects;
 import java.util.stream.IntStream;
 
+import static java.util.Objects.requireNonNull;
+
 /** Enumerator that reads from a Cassandra column family. */
 class CassandraEnumerator implements Enumerator<Object> {
   private final Iterator<Row> iterator;
@@ -86,7 +88,7 @@ class CassandraEnumerator implements Enumerator<Object> {
    * @param index Index of the field within the Row object
    */
   private @Nullable Object currentRowField(int index) {
-    assert current != null;
+    requireNonNull(current, "current");
     final Object o =
          current.get(index,
              CodecRegistry.DEFAULT.codecFor(
diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraFilter.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraFilter.java
index 117c79a99c..f357079d61 100644
--- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraFilter.java
+++ b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraFilter.java
@@ -46,12 +46,13 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Objects;
 import java.util.Set;
 
 import static org.apache.calcite.util.DateTimeStringUtils.ISO_DATETIME_FRACTIONAL_SECOND_FORMAT;
 import static org.apache.calcite.util.DateTimeStringUtils.getDateFormatter;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Implementation of a {@link org.apache.calcite.rel.core.Filter}
  * relational expression in Cassandra.
@@ -92,7 +93,8 @@ public class CassandraFilter extends Filter implements CassandraRel {
 
   @Override public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner,
       RelMetadataQuery mq) {
-    return super.computeSelfCost(planner, mq).multiplyBy(0.1);
+    final RelOptCost cost = requireNonNull(super.computeSelfCost(planner, mq));
+    return cost.multiplyBy(0.1);
   }
 
   @Override public CassandraFilter copy(RelTraitSet traitSet, RelNode input,
@@ -297,7 +299,7 @@ public class CassandraFilter extends Filter implements CassandraRel {
       String valueString = value.toString();
       if (value instanceof String) {
         RelDataTypeField field =
-            Objects.requireNonNull(rowType.getField(name, true, false));
+            requireNonNull(rowType.getField(name, true, false));
         SqlTypeName typeName = field.getType().getSqlTypeName();
         if (typeName != SqlTypeName.CHAR) {
           valueString = "'" + valueString + "'";
diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraProject.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraProject.java
index 947d6e5cd0..0ee42eec05 100644
--- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraProject.java
+++ b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraProject.java
@@ -36,6 +36,8 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Implementation of {@link org.apache.calcite.rel.core.Project}
  * relational expression in Cassandra.
@@ -56,7 +58,8 @@ public class CassandraProject extends Project implements CassandraRel {
 
   @Override public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner,
       RelMetadataQuery mq) {
-    return super.computeSelfCost(planner, mq).multiplyBy(0.1);
+    final RelOptCost cost = super.computeSelfCost(planner, mq);
+    return requireNonNull(cost, "cost").multiplyBy(0.1);
   }
 
   @Override public void implement(Implementor implementor) {
@@ -66,9 +69,9 @@ public class CassandraProject extends Project implements CassandraRel {
             CassandraRules.cassandraFieldNames(getInput().getRowType()));
     final Map<String, String> fields = new LinkedHashMap<>();
     for (Pair<RexNode, String> pair : getNamedProjects()) {
-      assert pair.left != null;
+      final RexNode node = pair.left;
       final String name = pair.right;
-      final String originalName = pair.left.accept(translator);
+      final String originalName = node.accept(translator);
       fields.put(originalName, name);
     }
     implementor.add(fields, null);
diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSchema.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSchema.java
index 31e22b0e3e..5462f86a20 100644
--- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSchema.java
+++ b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSchema.java
@@ -62,11 +62,12 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Optional;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Schema mapped onto a Cassandra column family.
  */
@@ -297,7 +298,7 @@ public class CassandraSchema extends AbstractSchema {
           + "WHERE keyspace_name='" + keyspace + "' AND view_name='"
           + view.getName().asInternal() + "'";
 
-      Row whereClauseRow = Objects.requireNonNull(session.execute(whereQuery).one());
+      Row whereClauseRow = requireNonNull(session.execute(whereQuery).one());
 
       queryBuilder.append(" WHERE ")
           .append(whereClauseRow.getString(0));
diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSchemaFactory.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSchemaFactory.java
index d392c80a6a..1ad7b119ff 100644
--- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSchemaFactory.java
+++ b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSchemaFactory.java
@@ -34,6 +34,8 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
+import static java.lang.Integer.parseInt;
+
 /**
  * Factory that creates a {@link CassandraSchema}.
  */
@@ -107,7 +109,7 @@ public class CassandraSchemaFactory implements SchemaFactory {
     if (map.containsKey("port")) {
       Object portObj = map.get("port");
       if (portObj instanceof String) {
-        return Integer.parseInt((String) portObj);
+        return parseInt((String) portObj);
       } else {
         return (int) portObj;
       }
diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSort.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSort.java
index 04bd4781cc..d897cce52c 100644
--- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSort.java
+++ b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSort.java
@@ -33,6 +33,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 import java.util.ArrayList;
 import java.util.List;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Implementation of {@link org.apache.calcite.rel.core.Sort}
  * relational expression in Cassandra.
@@ -48,7 +50,7 @@ public class CassandraSort extends Sort implements CassandraRel {
 
   @Override public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner,
       RelMetadataQuery mq) {
-    RelOptCost cost = super.computeSelfCost(planner, mq);
+    RelOptCost cost = requireNonNull(super.computeSelfCost(planner, mq));
     if (!collation.getFieldCollations().isEmpty()) {
       return cost.multiplyBy(0.05);
     } else {
diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraTable.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraTable.java
index b5f3c4c6bb..c28ada76e9 100644
--- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraTable.java
+++ b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraTable.java
@@ -57,9 +57,9 @@ import static java.util.Objects.requireNonNull;
 public class CassandraTable extends AbstractQueryableTable
     implements TranslatableTable {
   final RelProtoDataType protoRowType;
-  List<String> partitionKeys;
-  List<String> clusteringKeys;
-  List<RelFieldCollation> clusteringOrder;
+  final List<String> partitionKeys;
+  final List<String> clusteringKeys;
+  final List<RelFieldCollation> clusteringOrder;
   private final Optional<String> keyspace;
   private final String columnFamily;
 
diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraToEnumerableConverter.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraToEnumerableConverter.java
index f900cd6ee7..f99951a7a5 100644
--- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraToEnumerableConverter.java
+++ b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraToEnumerableConverter.java
@@ -30,6 +30,7 @@ import org.apache.calcite.plan.ConventionTraitDef;
 import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelOptCost;
 import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptTable;
 import org.apache.calcite.plan.RelTraitSet;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.convert.ConverterImpl;
@@ -46,7 +47,8 @@ import java.util.AbstractList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Relational expression representing a scan of a table in a Cassandra data source.
@@ -68,7 +70,8 @@ public class CassandraToEnumerableConverter
 
   @Override public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner,
       RelMetadataQuery mq) {
-    return super.computeSelfCost(planner, mq).multiplyBy(.1);
+    final RelOptCost cost = requireNonNull(super.computeSelfCost(planner, mq));
+    return cost.multiplyBy(.1);
   }
 
   @Override public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
@@ -103,10 +106,12 @@ public class CassandraToEnumerableConverter
     }
     final Expression selectFields =
         list.append("selectFields", constantArrayList(selectList, Pair.class));
+    final RelOptTable cassandraTable =
+        requireNonNull(cassandraImplementor.table);
     final Expression table =
         list.append("table",
-            Objects.requireNonNull(
-                cassandraImplementor.table.getExpression(
+            requireNonNull(
+                cassandraTable.getExpression(
                     CassandraTable.CassandraQueryable.class)));
     final Expression predicates =
         list.append("predicates",
diff --git a/cassandra/src/test/java/org/apache/calcite/test/CassandraExtension.java b/cassandra/src/test/java/org/apache/calcite/test/CassandraExtension.java
index fc635dd170..fa66f78edc 100644
--- a/cassandra/src/test/java/org/apache/calcite/test/CassandraExtension.java
+++ b/cassandra/src/test/java/org/apache/calcite/test/CassandraExtension.java
@@ -41,11 +41,13 @@ import org.junit.jupiter.api.extension.ParameterResolver;
 import java.io.IOException;
 import java.io.UncheckedIOException;
 import java.lang.reflect.Field;
+import java.net.URL;
 import java.time.Duration;
 import java.util.Locale;
-import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * JUnit5 extension to start and stop embedded Cassandra server.
  *
@@ -83,9 +85,9 @@ class CassandraExtension implements ParameterResolver, ExecutionCondition {
   }
 
   static ImmutableMap<String, String> getDataset(String resourcePath) {
+    URL u = CassandraExtension.class.getResource(resourcePath);
     return ImmutableMap.of("model",
-        Sources.of(Objects.requireNonNull(CassandraExtension.class.getResource(resourcePath)))
-            .file().getAbsolutePath());
+        Sources.of(requireNonNull(u, "u")).file().getAbsolutePath());
   }
 
   /** Registers a Cassandra resource in root context, so it can be shared with
diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj
index 49ea217d15..216c3e0b02 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -1745,10 +1745,10 @@ SqlNode SqlInsert() :
     (
         LOOKAHEAD(2)
         p = ParenthesizedCompoundIdentifierList() {
-            if (p.right.size() > 0) {
+            if (!p.right.isEmpty()) {
                 tableRef = extend(tableRef, p.right);
             }
-            if (p.left.size() > 0) {
+            if (!p.left.isEmpty()) {
                 columnList = p.left;
             } else {
                 columnList = null;
diff --git a/core/src/main/java/org/apache/calcite/DataContexts.java b/core/src/main/java/org/apache/calcite/DataContexts.java
index 93d45760fe..b7e7f3fea2 100644
--- a/core/src/main/java/org/apache/calcite/DataContexts.java
+++ b/core/src/main/java/org/apache/calcite/DataContexts.java
@@ -109,8 +109,8 @@ public class DataContexts {
 
   /** Implementation of {@link DataContext} backed by a Map. */
   private static class DataContextImpl extends MapDataContext {
-    private CalciteConnection connection;
-    private @Nullable SchemaPlus rootSchema;
+    private final CalciteConnection connection;
+    private final @Nullable SchemaPlus rootSchema;
 
     DataContextImpl(CalciteConnection connection,
         @Nullable SchemaPlus rootSchema, Map<String, Object> map) {
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java
index 1020838443..3bf60922ee 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java
@@ -356,7 +356,7 @@ public class EnumUtils {
       }
     } else {
       int j = 0;
-      for (int i = 0; i < expressions.size(); i++) {
+      for (Expression expression : expressions) {
         Class<?> type;
         if (!targetTypes[j].isArray()) {
           type = targetTypes[j];
@@ -364,7 +364,7 @@ public class EnumUtils {
         } else {
           type = targetTypes[j].getComponentType();
         }
-        list.add(fromInternal(expressions.get(i), type));
+        list.add(fromInternal(expression, type));
       }
     }
     return list;
@@ -453,7 +453,7 @@ public class EnumUtils {
               "to" + SqlFunctions.initcap(toPrimitive.getPrimitiveName()),
               operand);
         default:
-          // Generate "Short.parseShort(x)".
+          // Generate "parseShort(x)".
           return Expressions.call(
               toPrimitive.getBoxClass(),
               "parse" + SqlFunctions.initcap(toPrimitive.getPrimitiveName()),
@@ -993,7 +993,7 @@ public class EnumUtils {
     }
 
     @Override public boolean moveNext() {
-      return initialized ? list.size() > 0 : inputEnumerator.moveNext();
+      return initialized ? !list.isEmpty() : inputEnumerator.moveNext();
     }
 
     @Override public void reset() {
@@ -1133,7 +1133,7 @@ public class EnumUtils {
     }
 
     @Override public @Nullable Object[] current() {
-      if (list.size() > 0) {
+      if (!list.isEmpty()) {
         return takeOne();
       } else {
         @Nullable Object[] current = inputEnumerator.current();
@@ -1155,7 +1155,7 @@ public class EnumUtils {
     }
 
     @Override public boolean moveNext() {
-      return list.size() > 0 || inputEnumerator.moveNext();
+      return !list.isEmpty() || inputEnumerator.moveNext();
     }
 
     @Override public void reset() {
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAsofJoin.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAsofJoin.java
index f59ea1e409..d7cb7b4cdb 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAsofJoin.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAsofJoin.java
@@ -128,14 +128,14 @@ public class EnumerableAsofJoin extends AsofJoin implements EnumerableRel {
     return planner.getCostFactory().makeCost(rowCount, 0, 0);
   }
 
-  /** Generate the function that compares two rows from the right collection on their
-   * timestamp field.
+  /** Generates the function that compares two rows from the right collection on
+   * their timestamp field.
    *
    * @param rightCollectionType  Type of data in right collection.
    * @param kind                 Comparison kind.
    * @param timestampFieldIndex  Index of the field that is the timestamp field.
    */
-  private Expression generateTimestampComparator(
+  private static Expression generateTimestampComparator(
       PhysType rightCollectionType, SqlKind kind, int timestampFieldIndex) {
     RelFieldCollation.Direction direction;
     switch (kind) {
@@ -159,7 +159,7 @@ public class EnumerableAsofJoin extends AsofJoin implements EnumerableRel {
     return rightCollectionType.generateComparator(collation);
   }
 
-  /** Extract from a comparison 'call' the index of the field from
+  /** Extracts from a comparison 'call' the index of the field from
    * the inner collection that is used in the comparison. */
   private int getTimestampFieldIndex(RexCall call) {
     int timestampFieldIndex;
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableConvention.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableConvention.java
index 38678cf298..cdcba81653 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableConvention.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableConvention.java
@@ -28,8 +28,6 @@ import org.apache.calcite.rel.RelCollations;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.core.RelFactories;
 
-import org.checkerframework.checker.nullness.qual.Nullable;
-
 import static java.util.Objects.requireNonNull;
 
 /**
@@ -55,7 +53,7 @@ public enum EnumerableConvention implements Convention {
     return "ENUMERABLE";
   }
 
-  @Override public @Nullable RelNode enforce(
+  @Override public RelNode enforce(
       final RelNode input,
       final RelTraitSet required) {
     RelNode rel = input;
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java
index c92de30547..5f32ab1c71 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java
@@ -57,9 +57,10 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Modifier;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Relational expression that converts an enumerable input to interpretable
  * calling convention.
@@ -135,7 +136,8 @@ public class EnumerableInterpretable extends ConverterImpl
       InvocationTargetException, InstantiationException, IllegalAccessException {
     ICompilerFactory compilerFactory;
     ClassLoader classLoader =
-        Objects.requireNonNull(EnumerableInterpretable.class.getClassLoader(), "classLoader");
+        requireNonNull(EnumerableInterpretable.class.getClassLoader(),
+            "classLoader");
     try {
       compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(classLoader);
     } catch (Exception e) {
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
index 97eae019d3..e0749a981c 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
@@ -59,6 +59,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 import static org.apache.calcite.rel.RelCollations.containsOrderless;
 
 import static java.util.Objects.requireNonNull;
@@ -94,7 +96,8 @@ public class EnumerableMergeJoin extends Join implements EnumerableRel {
 
     final List<RelCollation> collations =
         traits.getTraits(RelCollationTraitDef.INSTANCE);
-    assert collations != null && collations.size() > 0;
+    requireNonNull(collations, "collations");
+    checkArgument(!collations.isEmpty());
     ImmutableIntList rightKeys = joinInfo.rightKeys
         .incr(left.getRowType().getFieldCount());
     // Currently it has very limited ability to represent the equivalent traits
@@ -347,11 +350,9 @@ public class EnumerableMergeJoin extends Join implements EnumerableRel {
       keyMap.put(sourceKeys.get(i), targetKeys.get(i));
     }
 
-    Mappings.TargetMapping mapping =
-        Mappings.target(keyMap,
-            (left2Right ? left : right).getRowType().getFieldCount(),
-            (left2Right ? right : left).getRowType().getFieldCount());
-    return mapping;
+    return Mappings.target(keyMap,
+        (left2Right ? left : right).getRowType().getFieldCount(),
+        (left2Right ? right : left).getRowType().getFieldCount());
   }
 
   /**
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoinRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoinRule.java
index 406152da6c..4137f6b74b 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoinRule.java
@@ -65,7 +65,7 @@ class EnumerableMergeJoinRule extends ConverterRule {
       // EnumerableMergeJoin only supports certain join types.
       return null;
     }
-    if (info.pairs().size() == 0) {
+    if (info.pairs().isEmpty()) {
       // EnumerableMergeJoin CAN support cartesian join, but disable it for now.
       return null;
     }
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMinus.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMinus.java
index e9c45c9641..33952937d1 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMinus.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMinus.java
@@ -53,7 +53,7 @@ public class EnumerableMinus extends Minus implements EnumerableRel {
           builder.append(
               "child" + ord.i,
               result.block);
-      assert childExp != null : "childExp must not be null";
+      requireNonNull(childExp, "childExp");
 
       if (minusExp == null) {
         minusExp = childExp;
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModify.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModify.java
index d6c90083f0..186ec6903f 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModify.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModify.java
@@ -40,6 +40,10 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
+import static java.util.Objects.requireNonNull;
+
 /** Implementation of {@link org.apache.calcite.rel.core.TableModify} in
  * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */
 public class EnumerableTableModify extends TableModify
@@ -83,9 +87,11 @@ public class EnumerableTableModify extends TableModify
         Expressions.parameter(Collection.class,
             builder.newName("collection"));
     final Expression expression = table.getExpression(ModifiableTable.class);
-    assert expression != null; // TODO: user error in validator
-    assert ModifiableTable.class.isAssignableFrom(
-        Types.toClass(expression.getType())) : expression.getType();
+    requireNonNull(expression, "expression"); // TODO: user error in validator
+    checkArgument(
+        ModifiableTable.class.isAssignableFrom(
+            Types.toClass(expression.getType())),
+        "not assignable from type %s", expression.getType());
     builder.add(
         Expressions.declare(
             Modifier.FINAL,
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTraitsUtils.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTraitsUtils.java
index b716cb5546..cc16ef98ed 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTraitsUtils.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTraitsUtils.java
@@ -43,7 +43,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Utilities for traits propagation.
@@ -70,14 +71,13 @@ class EnumerableTraitsUtils {
     if (node.isA(SqlKind.CAST)) {
       // Check whether it is a monotonic preserving cast
       final RexCall cast = (RexCall) node;
-      RelFieldCollation newFieldCollation = Objects.requireNonNull(RexUtil.apply(map, fc));
+      RelFieldCollation newFieldCollation =
+          requireNonNull(RexUtil.apply(map, fc));
       final RexCallBinding binding =
           RexCallBinding.create(typeFactory, cast,
               ImmutableList.of(RelCollations.of(newFieldCollation)));
-      if (cast.getOperator().getMonotonicity(binding)
-          == SqlMonotonicity.NOT_MONOTONIC) {
-        return false;
-      }
+      return cast.getOperator().getMonotonicity(binding)
+          != SqlMonotonicity.NOT_MONOTONIC;
     }
 
     return true;
@@ -140,7 +140,7 @@ class EnumerableTraitsUtils {
       }
     }
 
-    if (collationFieldsToDerive.size() > 0) {
+    if (!collationFieldsToDerive.isEmpty()) {
       final RelCollation newCollation = RelCollations
           .of(collationFieldsToDerive).apply(mapping);
       return Pair.of(currentTraits.replace(newCollation),
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
index c180e3fc0f..6197420b05 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
@@ -529,7 +529,7 @@ public class EnumerableWindow extends Window implements EnumerableRel {
     return implementor.result(inputPhysType, builder.toBlock());
   }
 
-  private Statement buildExcludeGuard(Group group, Expression comparator,
+  private static Statement buildExcludeGuard(Group group, Expression comparator,
       ParameterExpression currentRow,
       DeclarationStatement jDecl, Expression rows, BlockStatement forBlock) {
     if (group.exclude == RexWindowExclusion.EXCLUDE_CURRENT_ROW) {
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
index 40c09cbc86..a5c86b939c 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
@@ -277,7 +277,7 @@ public enum JavaRowFormat {
       return Expressions.assign(e, value);
     }
 
-    @Override public @Nullable Expression copy(ParameterExpression parameter,
+    @Override public Expression copy(ParameterExpression parameter,
         ParameterExpression outputArray, int outputStartIndex, int length) {
       return Expressions.call(ARRAY_COPY.method, parameter, Expressions.constant(0),
           outputArray, Expressions.constant(outputStartIndex), Expressions.constant(length));
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index d3f49d4349..346f3b53f5 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
@@ -2600,7 +2600,7 @@ public class RexImpTable {
 
     @Override Expression implementSafe(final RexToLixTranslator translator,
         final RexCall call, final List<Expression> argValueList) {
-      List<Expression> args = new ArrayList<Expression>();
+      List<Expression> args = new ArrayList<>();
       args.add(convertType(argValueList.get(0), call.operands.get(0)));
       // SAFE_NEGATE only has one argument so create constant -1L to use
       // SAFE_MULTIPLY implementation.
@@ -2893,7 +2893,7 @@ public class RexImpTable {
       Expression errorBehavior = Expressions.constant(SqlJsonValueEmptyOrErrorBehavior.NULL);
       Expression defaultValueOnError = Expressions.constant(null);
       // Patched up with user defines.
-      if (leftExprs.size() > 0) {
+      if (!leftExprs.isEmpty()) {
         for (int i = 0; i < leftExprs.size(); i++) {
           Expression expr = leftExprs.get(i);
           final Object exprVal = translator.getLiteralValue(expr);
@@ -4291,7 +4291,7 @@ public class RexImpTable {
       }
       operand0 = operands.left;
       operand1 = operands.right;
-      boolean nonPositiveIsNull = library == SqlLibrary.MYSQL ? true : false;
+      boolean nonPositiveIsNull = library == SqlLibrary.MYSQL;
       final Expressions.FluentList<Expression> list = Expressions.list(operand0);
       switch (call.getOperator().getName()) {
       case "LOG":
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java
index ba1abce1c0..b3ad55e2f7 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java
@@ -42,7 +42,8 @@ public abstract class WinAggAddContextImpl extends WinAggResultContextImpl
   @Deprecated // to be removed before 2.0
   protected WinAggAddContextImpl(BlockBuilder block, List<Expression> accumulator,
       com.google.common.base.Function<BlockBuilder, WinAggFrameResultContext> frame) {
-    this(block, accumulator, (Function<BlockBuilder, WinAggFrameResultContext>) frame::apply);
+    this(block, accumulator,
+        (Function<BlockBuilder, WinAggFrameResultContext>) frame);
   }
 
   @Override public final RexToLixTranslator rowTranslator() {
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java
index 83700714e4..52f4a346fc 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java
@@ -55,7 +55,7 @@ public abstract class WinAggResultContextImpl extends AggResultContextImpl
       List<Expression> accumulator,
       com.google.common.base.Function<BlockBuilder, WinAggFrameResultContext> frameContextBuilder) {
     this(block, accumulator,
-        (Function<BlockBuilder, WinAggFrameResultContext>) frameContextBuilder::apply);
+        (Function<BlockBuilder, WinAggFrameResultContext>) frameContextBuilder);
   }
 
   private WinAggFrameResultContext getFrame() {
diff --git a/core/src/main/java/org/apache/calcite/adapter/java/ReflectiveSchema.java b/core/src/main/java/org/apache/calcite/adapter/java/ReflectiveSchema.java
index 5e317fe6a1..24dbe8a3d2 100644
--- a/core/src/main/java/org/apache/calcite/adapter/java/ReflectiveSchema.java
+++ b/core/src/main/java/org/apache/calcite/adapter/java/ReflectiveSchema.java
@@ -75,7 +75,7 @@ import static java.util.Objects.requireNonNull;
  */
 public class ReflectiveSchema
     extends AbstractSchema {
-  private final Class clazz;
+  private final Class<?> clazz;
   private final Object target;
   private @MonotonicNonNull Map<String, Table> tableMap;
   private @MonotonicNonNull Multimap<String, Function> functionMap;
@@ -134,9 +134,10 @@ public class ReflectiveSchema
               "Error while accessing field " + field, e);
         }
         requireNonNull(rc, () -> "field must not be null: " + field);
-        FieldTable table =
-            (FieldTable) tableMap.get(Util.last(rc.getSourceQualifiedName()));
-        assert table != null;
+        FieldTable<?> table =
+            (FieldTable<?>)
+                requireNonNull(
+                    tableMap.get(Util.last(rc.getSourceQualifiedName())));
         List<RelReferentialConstraint> referentialConstraints =
             table.getStatistic().getReferentialConstraints();
         if (referentialConstraints == null) {
@@ -214,9 +215,9 @@ public class ReflectiveSchema
     return new FieldTable<>(field, elementType, enumerable, statistic);
   }
 
-  /** Deduces the element type of a collection;
+  /** Deduces a collection's element type;
    * same logic as {@link #toEnumerable}. */
-  private static @Nullable Type getElementType(Class clazz) {
+  private static @Nullable Type getElementType(Class<?> clazz) {
     if (clazz.isArray()) {
       return clazz.getComponentType();
     }
@@ -226,16 +227,17 @@ public class ReflectiveSchema
     return null; // not a collection/array/iterable
   }
 
-  private static Enumerable toEnumerable(final Object o) {
+  @SuppressWarnings("unchecked")
+  private static <T> Enumerable<T> toEnumerable(final Object o) {
     if (o.getClass().isArray()) {
       if (o instanceof Object[]) {
-        return Linq4j.asEnumerable((Object[]) o);
+        return Linq4j.asEnumerable((T[]) o);
       } else {
-        return Linq4j.asEnumerable(Primitive.asList(o));
+        return Linq4j.asEnumerable((List<T>) Primitive.asList(o));
       }
     }
     if (o instanceof Iterable) {
-      return Linq4j.asEnumerable((Iterable) o);
+      return Linq4j.asEnumerable((Iterable<T>) o);
     }
     throw new RuntimeException(
         "Cannot convert " + o.getClass() + " into a Enumerable");
@@ -256,7 +258,7 @@ public class ReflectiveSchema
       implements Table, ScannableTable {
     private final Enumerable enumerable;
 
-    ReflectiveTable(Type elementType, Enumerable enumerable) {
+    ReflectiveTable(Type elementType, Enumerable<?> enumerable) {
       super(elementType);
       this.enumerable = enumerable;
     }
diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcCatalogSchema.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcCatalogSchema.java
index 202bf0e017..ba63e0f494 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcCatalogSchema.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcCatalogSchema.java
@@ -106,7 +106,7 @@ public class JdbcCatalogSchema extends AbstractSchema implements Wrapper {
   private SubSchemaMap computeSubSchemaMap() {
     final ImmutableMap.Builder<String, Schema> builder =
         ImmutableMap.builder();
-    String defaultSchemaName;
+    @Nullable String defaultSchemaName;
     try (Connection connection = dataSource.getConnection();
          ResultSet resultSet =
              connection.getMetaData().getSchemas(catalog, null)) {
@@ -129,7 +129,7 @@ public class JdbcCatalogSchema extends AbstractSchema implements Wrapper {
   }
 
   /** Returns the name of the default sub-schema. */
-  public String getDefaultSubSchemaName() {
+  public @Nullable String getDefaultSubSchemaName() {
     return subSchemaMapSupplier.get().defaultSchemaName;
   }
 
@@ -151,10 +151,10 @@ public class JdbcCatalogSchema extends AbstractSchema implements Wrapper {
 
   /** Contains sub-schemas by name, and the name of the default schema. */
   private static class SubSchemaMap {
-    final String defaultSchemaName;
+    final @Nullable String defaultSchemaName;
     final ImmutableMap<String, Schema> map;
 
-    private SubSchemaMap(String defaultSchemaName,
+    private SubSchemaMap(@Nullable String defaultSchemaName,
         ImmutableMap<String, Schema> map) {
       this.defaultSchemaName = defaultSchemaName;
       this.map = map;
diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java
index 176939c915..963f6bf5e7 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java
@@ -67,6 +67,7 @@ import java.util.Set;
 import java.util.function.BiFunction;
 import javax.sql.DataSource;
 
+import static java.lang.Integer.parseInt;
 import static java.util.Objects.requireNonNull;
 
 /**
@@ -464,10 +465,10 @@ public class JdbcSchema implements Schema, Wrapper {
         typeString = typeString.substring(0, open);
         int comma = rest.indexOf(",");
         if (comma >= 0) {
-          precision = Integer.parseInt(rest.substring(0, comma));
-          scale = Integer.parseInt(rest.substring(comma));
+          precision = parseInt(rest.substring(0, comma));
+          scale = parseInt(rest.substring(comma));
         } else {
-          precision = Integer.parseInt(rest);
+          precision = parseInt(rest);
         }
       }
     }
diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTableScan.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTableScan.java
index 7cab213309..d2e49872fe 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTableScan.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTableScan.java
@@ -27,7 +27,6 @@ import org.apache.calcite.rel.hint.RelHint;
 import com.google.common.collect.ImmutableList;
 
 import java.util.List;
-import java.util.Objects;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 
@@ -46,7 +45,7 @@ public class JdbcTableScan extends TableScan implements JdbcRel {
       JdbcTable jdbcTable,
       JdbcConvention jdbcConvention) {
     super(cluster, cluster.traitSetOf(jdbcConvention), hints, table);
-    this.jdbcTable = Objects.requireNonNull(jdbcTable, "jdbcTable");
+    this.jdbcTable = requireNonNull(jdbcTable, "jdbcTable");
   }
 
   @Override public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcToEnumerableConverter.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcToEnumerableConverter.java
index 80cf32d992..11b676bd8a 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcToEnumerableConverter.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcToEnumerableConverter.java
@@ -238,7 +238,7 @@ public class JdbcToEnumerableConverter
     boolean offset = false;
     switch (calendarPolicy) {
     case LOCAL:
-      assert calendar_ != null : "calendar must not be null";
+      requireNonNull(calendar_, "calendar_");
       dateTimeArgs.add(calendar_);
       break;
     case NULL:
diff --git a/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java b/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java
index 4d454c69fa..ebd7a5c02d 100644
--- a/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java
+++ b/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java
@@ -32,6 +32,8 @@ import java.util.stream.Stream;
 
 import static com.google.common.base.MoreObjects.firstNonNull;
 
+import static java.lang.Boolean.parseBoolean;
+import static java.lang.Integer.parseInt;
 import static java.util.Objects.requireNonNull;
 
 /**
@@ -423,7 +425,7 @@ public final class CalciteSystemProperty<T> {
     // Note that "" -> true (convenient for command-lines flags like '-Dflag')
     return new CalciteSystemProperty<>(key,
         v -> v == null ? defaultValue
-            : v.isEmpty() || Boolean.parseBoolean(v));
+            : v.isEmpty() || parseBoolean(v));
   }
 
   private static CalciteSystemProperty<Integer> intProperty(String key, int defaultValue) {
@@ -448,7 +450,7 @@ public final class CalciteSystemProperty<T> {
         return defaultValue;
       }
       try {
-        int intVal = Integer.parseInt(v);
+        int intVal = parseInt(v);
         return valueChecker.test(intVal) ? intVal : defaultValue;
       } catch (NumberFormatException nfe) {
         return defaultValue;
diff --git a/core/src/main/java/org/apache/calcite/config/Lex.java b/core/src/main/java/org/apache/calcite/config/Lex.java
index e486c1a94e..48ee133370 100644
--- a/core/src/main/java/org/apache/calcite/config/Lex.java
+++ b/core/src/main/java/org/apache/calcite/config/Lex.java
@@ -21,9 +21,10 @@ import org.apache.calcite.avatica.util.Quoting;
 
 import com.google.common.collect.ImmutableSet;
 
-import java.util.Objects;
 import java.util.Set;
 
+import static java.util.Objects.requireNonNull;
+
 /** Named, built-in lexical policy. A lexical policy describes how
  * identifiers are quoted, whether they are converted to upper- or
  * lower-case when they are read, and whether they are matched
@@ -89,9 +90,9 @@ public enum Lex {
       Casing quotedCasing,
       boolean caseSensitive,
       CharLiteralStyle... charLiteralStyles) {
-    this.quoting = Objects.requireNonNull(quoting, "quoting");
-    this.unquotedCasing = Objects.requireNonNull(unquotedCasing, "unquotedCasing");
-    this.quotedCasing = Objects.requireNonNull(quotedCasing, "quotedCasing");
+    this.quoting = requireNonNull(quoting, "quoting");
+    this.unquotedCasing = requireNonNull(unquotedCasing, "unquotedCasing");
+    this.quotedCasing = requireNonNull(quotedCasing, "quotedCasing");
     this.caseSensitive = caseSensitive;
     this.charLiteralStyles = ImmutableSet.copyOf(charLiteralStyles);
   }
diff --git a/core/src/main/java/org/apache/calcite/interpreter/Bindables.java b/core/src/main/java/org/apache/calcite/interpreter/Bindables.java
index 8d622ddcd4..069a2cade4 100644
--- a/core/src/main/java/org/apache/calcite/interpreter/Bindables.java
+++ b/core/src/main/java/org/apache/calcite/interpreter/Bindables.java
@@ -84,12 +84,13 @@ import org.immutables.value.Value;
 
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Set;
 import java.util.SortedSet;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Utilities pertaining to {@link BindableRel} and {@link BindableConvention}.
  */
@@ -218,8 +219,8 @@ public class Bindables {
         RelOptTable table, ImmutableList<RexNode> filters,
         ImmutableIntList projects) {
       super(cluster, traitSet, ImmutableList.of(), table);
-      this.filters = Objects.requireNonNull(filters, "filters");
-      this.projects = Objects.requireNonNull(projects, "projects");
+      this.filters = requireNonNull(filters, "filters");
+      this.projects = requireNonNull(projects, "projects");
       checkArgument(canHandle(table));
     }
 
diff --git a/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java b/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java
index 85569d65b6..6bd8bde4c1 100644
--- a/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java
+++ b/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java
@@ -131,7 +131,10 @@ public class Interpreter extends AbstractEnumerable<@Nullable Object[]>
     for (Map.Entry<RelNode, NodeInfo> entry : nodes.entrySet()) {
       final NodeInfo nodeInfo = entry.getValue();
       try {
-        assert nodeInfo.node != null : "node must not be null for nodeInfo, rel=" + nodeInfo.rel;
+        if (nodeInfo.node == null) {
+          throw new AssertionError("node must not be null for nodeInfo, rel="
+              + nodeInfo.rel);
+        }
         nodeInfo.node.run();
       } catch (InterruptedException e) {
         e.printStackTrace();
@@ -197,11 +200,11 @@ public class Interpreter extends AbstractEnumerable<@Nullable Object[]>
       this.list = list;
     }
 
-    @Override public void send(Row row) throws InterruptedException {
+    @Override public void send(Row row) {
       list.add(row);
     }
 
-    @Override public void end() throws InterruptedException {
+    @Override public void end() {
     }
 
     @SuppressWarnings("deprecation")
@@ -244,24 +247,23 @@ public class Interpreter extends AbstractEnumerable<@Nullable Object[]>
 
   /** Implementation of {@link Sink} using a {@link java.util.ArrayDeque}. */
   private static class DuplicatingSink implements Sink {
-    private List<ArrayDeque<Row>> queues;
+    private final List<ArrayDeque<Row>> queues;
 
     private DuplicatingSink(List<ArrayDeque<Row>> queues) {
       this.queues = ImmutableList.copyOf(queues);
     }
 
-    @Override public void send(Row row) throws InterruptedException {
+    @Override public void send(Row row) {
       for (ArrayDeque<Row> queue : queues) {
         queue.add(row);
       }
     }
 
-    @Override public void end() throws InterruptedException {
+    @Override public void end() {
     }
 
     @SuppressWarnings("deprecation")
-    @Override public void setSourceEnumerable(Enumerable<Row> enumerable)
-        throws InterruptedException {
+    @Override public void setSourceEnumerable(Enumerable<Row> enumerable) {
       // just copy over the source into the local list
       final Enumerator<Row> enumerator = enumerable.enumerator();
       while (enumerator.moveNext()) {
@@ -369,8 +371,7 @@ public class Interpreter extends AbstractEnumerable<@Nullable Object[]>
               + p.getClass());
         }
       }
-      final NodeInfo nodeInfo = nodes.get(p);
-      assert nodeInfo != null;
+      final NodeInfo nodeInfo = requireNonNull(nodes.get(p));
       nodeInfo.node = node;
       if (inputs != null) {
         for (int i = 0; i < inputs.size(); i++) {
diff --git a/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java b/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java
index bc0bf81649..bca4f85ef5 100644
--- a/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java
+++ b/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java
@@ -54,7 +54,8 @@ import java.io.StringReader;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Compiles a scalar expression ({@link RexNode}) to an expression that
@@ -200,7 +201,7 @@ public class JaninoRexCompiler implements Interpreter.ScalarCompiler {
       throws CompileException, IOException {
     ICompilerFactory compilerFactory;
     ClassLoader classLoader =
-        Objects.requireNonNull(JaninoRexCompiler.class.getClassLoader(), "classLoader");
+        requireNonNull(JaninoRexCompiler.class.getClassLoader(), "classLoader");
     try {
       compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(classLoader);
     } catch (Exception e) {
diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteConnection.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteConnection.java
index d350d46aa2..285d966641 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/CalciteConnection.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteConnection.java
@@ -22,6 +22,8 @@ import org.apache.calcite.jdbc.CalcitePrepare.Context;
 import org.apache.calcite.linq4j.QueryProvider;
 import org.apache.calcite.schema.SchemaPlus;
 
+import org.checkerframework.checker.nullness.qual.Nullable;
+
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Properties;
@@ -74,7 +76,7 @@ public interface CalciteConnection extends Connection, QueryProvider {
   @Override void setSchema(String schema) throws SQLException;
 
   // in java.sql.Connection from JDK 1.7, but declare here to allow other JDKs
-  @Override String getSchema() throws SQLException;
+  @Override @Nullable String getSchema() throws SQLException;
 
   CalciteConnectionConfig config();
 
diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
index 82be273877..4677801d4e 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
@@ -298,7 +298,7 @@ public class CalciteMetaImpl extends MetaImpl {
 
   private <E> MetaResultSet createResultSet(Enumerable<E> enumerable,
       Class clazz, List<String> names) {
-    assert names.size() > 0;
+    assert !names.isEmpty();
     final List<ColumnMetaData> columns = new ArrayList<>(names.size());
     final List<Field> fields = new ArrayList<>(names.size());
     final List<String> fieldNames = new ArrayList<>(names.size());
@@ -464,7 +464,7 @@ public class CalciteMetaImpl extends MetaImpl {
   Enumerable<MetaTable> tables(final MetaSchema schema_) {
     final CalciteMetaSchema schema = (CalciteMetaSchema) schema_;
     return Linq4j.asEnumerable(schema.calciteSchema.getTableNames())
-        .select((Function1<String, MetaTable>) name -> {
+        .select(name -> {
           final Table table =
               requireNonNull(schema.calciteSchema.getTable(name, true),
                   () -> "table " + name + " is not found (case sensitive)")
@@ -759,7 +759,7 @@ public class CalciteMetaImpl extends MetaImpl {
     final List rows =
         MetaImpl.collect(signature.cursorFactory,
             LimitIterator.of(iterator, fetchMaxRowCount),
-            new ArrayList<List<Object>>());
+            new ArrayList<>());
     boolean done = fetchMaxRowCount == 0 || rows.size() < fetchMaxRowCount;
     @SuppressWarnings("unchecked") List<Object> rows1 = (List<Object>) rows;
     return new Meta.Frame(offset, done, rows1);
@@ -832,15 +832,15 @@ public class CalciteMetaImpl extends MetaImpl {
             return statement;
           }
 
-          @Override public void clear() throws SQLException {}
+          @Override public void clear() {}
 
           @Override public void assign(Meta.Signature signature, Meta.@Nullable Frame firstFrame,
-              long updateCount) throws SQLException {
+              long updateCount) {
             this.signature = signature;
             this.updateCount = updateCount;
           }
 
-          @Override public void execute() throws SQLException {
+          @Override public void execute() {
             Signature signature = requireNonNull(this.signature, "signature");
             if (signature.statementType.canUpdate()) {
               final Iterable<Object> iterable =
@@ -873,8 +873,8 @@ public class CalciteMetaImpl extends MetaImpl {
     return DRIVER.connect(schema, typeFactory);
   }
 
-  @Override public boolean syncResults(StatementHandle h, QueryState state, long offset)
-      throws NoSuchStatementException {
+  @Override public boolean syncResults(StatementHandle h, QueryState state,
+      long offset) {
     // Doesn't have application in Calcite itself.
     throw new UnsupportedOperationException();
   }
diff --git a/core/src/main/java/org/apache/calcite/jdbc/JavaRecordType.java b/core/src/main/java/org/apache/calcite/jdbc/JavaRecordType.java
index da86efa819..72242d3934 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/JavaRecordType.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/JavaRecordType.java
@@ -24,6 +24,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 import java.util.List;
 import java.util.Objects;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Record type based on a Java class. The fields of the type are the fields
  * of the class.
@@ -36,7 +38,7 @@ public class JavaRecordType extends RelRecordType {
 
   public JavaRecordType(List<RelDataTypeField> fields, Class clazz) {
     super(fields);
-    this.clazz = Objects.requireNonNull(clazz, "clazz");
+    this.clazz = requireNonNull(clazz, "clazz");
   }
 
   @Override public boolean equals(@Nullable Object obj) {
diff --git a/core/src/main/java/org/apache/calcite/materialize/Lattice.java b/core/src/main/java/org/apache/calcite/materialize/Lattice.java
index 95ba02c355..e8e8de80d1 100644
--- a/core/src/main/java/org/apache/calcite/materialize/Lattice.java
+++ b/core/src/main/java/org/apache/calcite/materialize/Lattice.java
@@ -811,8 +811,7 @@ public class Lattice {
 
       // Get aliases.
       List<@Nullable String> aliases = new ArrayList<>();
-      SqlNode from = ((SqlSelect) parsed.sqlNode).getFrom();
-      assert from != null : "from must not be null";
+      SqlNode from = requireNonNull(((SqlSelect) parsed.sqlNode).getFrom());
       populateAliases(from, aliases, null);
 
       // Build a graph.
@@ -864,7 +863,7 @@ public class Lattice {
         }
         map.put(vertex.table, node);
       }
-      assert root != null;
+      requireNonNull(root, "root");
       final Fixer fixer = new Fixer();
       fixer.fixUp(root);
       baseColumns = fixer.columnList.build();
@@ -978,7 +977,7 @@ public class Lattice {
      */
     private Column resolveColumnByAlias(String name) {
       final ImmutableList<Column> list = columnsByAlias.get(name);
-      if (list == null || list.size() == 0) {
+      if (list.isEmpty()) {
         throw new RuntimeException("Unknown lattice column '" + name + "'");
       } else if (list.size() == 1) {
         return list.get(0);
diff --git a/core/src/main/java/org/apache/calcite/materialize/LatticeSpace.java b/core/src/main/java/org/apache/calcite/materialize/LatticeSpace.java
index 395da98d71..17c1c4d410 100644
--- a/core/src/main/java/org/apache/calcite/materialize/LatticeSpace.java
+++ b/core/src/main/java/org/apache/calcite/materialize/LatticeSpace.java
@@ -32,10 +32,11 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Set;
 import java.util.TreeSet;
 
+import static java.util.Objects.requireNonNull;
+
 /** Space within which lattices exist. */
 class LatticeSpace {
   final SqlStatisticProvider statisticProvider;
@@ -51,7 +52,8 @@ class LatticeSpace {
   final Map<LatticeTable, List<RexNode>> tableExpressions = new HashMap<>();
 
   LatticeSpace(SqlStatisticProvider statisticProvider) {
-    this.statisticProvider = Objects.requireNonNull(statisticProvider, "statisticProvider");
+    this.statisticProvider =
+        requireNonNull(statisticProvider, "statisticProvider");
   }
 
   /** Derives a unique name for a table, qualifying with schema name only if
@@ -168,7 +170,9 @@ class LatticeSpace {
       return fieldList.get(field).getName();
     } else {
       List<RexNode> rexNodes = tableExpressions.get(table);
-      assert rexNodes != null : "no expressions found for table " + table;
+      if (rexNodes == null) {
+        throw new AssertionError("no expressions found for table " + table);
+      }
       return rexNodes.get(field - fieldCount).toString();
     }
   }
diff --git a/core/src/main/java/org/apache/calcite/materialize/LatticeTable.java b/core/src/main/java/org/apache/calcite/materialize/LatticeTable.java
index d2cabd73d4..5e5bdaeb7d 100644
--- a/core/src/main/java/org/apache/calcite/materialize/LatticeTable.java
+++ b/core/src/main/java/org/apache/calcite/materialize/LatticeTable.java
@@ -22,7 +22,7 @@ import org.apache.calcite.util.Util;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
 
-import java.util.Objects;
+import static java.util.Objects.requireNonNull;
 
 /** Table registered in the graph. */
 public class LatticeTable {
@@ -30,8 +30,8 @@ public class LatticeTable {
   public final String alias;
 
   LatticeTable(RelOptTable table) {
-    t = Objects.requireNonNull(table, "table");
-    alias = Objects.requireNonNull(Util.last(table.getQualifiedName()));
+    t = requireNonNull(table, "table");
+    alias = requireNonNull(Util.last(table.getQualifiedName()));
   }
 
   @Override public int hashCode() {
diff --git a/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java b/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java
index 89a6ea2bf4..0475fc40aa 100644
--- a/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java
+++ b/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java
@@ -31,6 +31,8 @@ import java.util.Objects;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Actor that manages the state of materializations in the system.
  */
@@ -55,7 +57,7 @@ class MaterializationActor {
   static class Materialization {
     final MaterializationKey key;
     final CalciteSchema rootSchema;
-    CalciteSchema.@Nullable TableEntry materializedTable;
+    final CalciteSchema.@Nullable TableEntry materializedTable;
     final String sql;
     final RelDataType rowType;
     final @Nullable List<String> viewSchemaPath;
@@ -77,12 +79,12 @@ class MaterializationActor {
         String sql,
         RelDataType rowType,
         @Nullable List<String> viewSchemaPath) {
-      this.key = key;
-      this.rootSchema = Objects.requireNonNull(rootSchema, "rootSchema");
+      this.key = requireNonNull(key, "key");
+      this.rootSchema = requireNonNull(rootSchema, "rootSchema");
       checkArgument(rootSchema.isRoot(), "must be root schema");
       this.materializedTable = materializedTable; // may be null
-      this.sql = sql;
-      this.rowType = rowType;
+      this.sql = requireNonNull(sql, "sql");
+      this.rowType = requireNonNull(rowType, "rowType");
       this.viewSchemaPath = viewSchemaPath;
     }
   }
diff --git a/core/src/main/java/org/apache/calcite/materialize/MutableNode.java b/core/src/main/java/org/apache/calcite/materialize/MutableNode.java
index 1d9faa9b32..eb3e788621 100644
--- a/core/src/main/java/org/apache/calcite/materialize/MutableNode.java
+++ b/core/src/main/java/org/apache/calcite/materialize/MutableNode.java
@@ -23,13 +23,14 @@ import com.google.common.collect.Ordering;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 
+import static java.util.Objects.requireNonNull;
+
 /** Mutable version of {@link LatticeNode}, used while a graph is being
  * built. */
 class MutableNode {
@@ -70,12 +71,12 @@ class MutableNode {
   /** Creates a non-root node. */
   @SuppressWarnings("argument.type.incompatible")
   MutableNode(LatticeTable table, @Nullable MutableNode parent, @Nullable Step step) {
-    this.table = Objects.requireNonNull(table, "table");
+    this.table = requireNonNull(table, "table");
     this.parent = parent;
     this.step = step;
     if (parent != null) {
       parent.children.add(this);
-      Collections.sort(parent.children, ORDERING);
+      parent.children.sort(ORDERING);
     }
   }
 
diff --git a/core/src/main/java/org/apache/calcite/materialize/ProfilerLatticeStatisticProvider.java b/core/src/main/java/org/apache/calcite/materialize/ProfilerLatticeStatisticProvider.java
index 29d3457ae7..0535188e73 100644
--- a/core/src/main/java/org/apache/calcite/materialize/ProfilerLatticeStatisticProvider.java
+++ b/core/src/main/java/org/apache/calcite/materialize/ProfilerLatticeStatisticProvider.java
@@ -32,9 +32,10 @@ import com.google.common.collect.ImmutableList;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Objects;
 import java.util.function.Supplier;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Implementation of {@link LatticeStatisticProvider} that uses a
  * {@link org.apache.calcite.profile.Profiler}.
@@ -46,7 +47,7 @@ class ProfilerLatticeStatisticProvider implements LatticeStatisticProvider {
 
   /** Creates a ProfilerLatticeStatisticProvider. */
   private ProfilerLatticeStatisticProvider(Lattice lattice) {
-    Objects.requireNonNull(lattice, "lattice");
+    requireNonNull(lattice, "lattice");
     this.profile = Suppliers.memoize(() -> {
       final ProfilerImpl profiler =
           ProfilerImpl.builder()
diff --git a/core/src/main/java/org/apache/calcite/materialize/Step.java b/core/src/main/java/org/apache/calcite/materialize/Step.java
index 2a57d76f03..ecbabb32e2 100644
--- a/core/src/main/java/org/apache/calcite/materialize/Step.java
+++ b/core/src/main/java/org/apache/calcite/materialize/Step.java
@@ -31,6 +31,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 import java.util.List;
 import java.util.Objects;
 
+import static java.util.Objects.requireNonNull;
+
 /** Edge in the join graph.
  *
  * <p>It is directed: the "parent" must be the "many" side containing the
@@ -51,7 +53,7 @@ class Step extends DefaultEdge {
       List<IntPair> keys, String keyString) {
     super(source, target);
     this.keys = ImmutableList.copyOf(keys);
-    this.keyString = Objects.requireNonNull(keyString, "keyString");
+    this.keyString = requireNonNull(keyString, "keyString");
     assert IntPair.ORDERING.isStrictlyOrdered(keys); // ordered and unique
   }
 
@@ -147,7 +149,7 @@ class Step extends DefaultEdge {
 
     @SuppressWarnings("type.argument.type.incompatible")
     Factory(@UnderInitialization LatticeSpace space) {
-      this.space = Objects.requireNonNull(space, "space");
+      this.space = requireNonNull(space, "space");
     }
 
     @Override public Step createEdge(LatticeTable source, LatticeTable target) {
diff --git a/core/src/main/java/org/apache/calcite/model/JsonView.java b/core/src/main/java/org/apache/calcite/model/JsonView.java
index a86c56e1c3..9c84f430c0 100644
--- a/core/src/main/java/org/apache/calcite/model/JsonView.java
+++ b/core/src/main/java/org/apache/calcite/model/JsonView.java
@@ -22,7 +22,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * View schema element.
@@ -96,7 +97,7 @@ public class JsonView extends JsonTable {
       @JsonProperty("path") @Nullable List<String> path,
       @JsonProperty("modifiable") @Nullable Boolean modifiable) {
     super(name, stream);
-    this.sql = Objects.requireNonNull(sql, "sql");
+    this.sql = requireNonNull(sql, "sql");
     this.path = path;
     this.modifiable = modifiable;
   }
diff --git a/core/src/main/java/org/apache/calcite/model/ModelHandler.java b/core/src/main/java/org/apache/calcite/model/ModelHandler.java
index 128869afe8..cd99332f75 100644
--- a/core/src/main/java/org/apache/calcite/model/ModelHandler.java
+++ b/core/src/main/java/org/apache/calcite/model/ModelHandler.java
@@ -119,7 +119,7 @@ public class ModelHandler {
    *
    * @param schema Schema to add to
    * @param functionName Name of function; null to derived from method name
-   * @param path Path to look for functions
+   * @param unusedPath Path to look for functions (currently ignored)
    * @param className Class to inspect for methods that may be user-defined
    *                  functions
    * @param methodName Method name;
@@ -128,8 +128,9 @@ public class ModelHandler {
    * @param upCase Whether to convert method names to upper case, so that they
    *               can be called without using quotes
    */
-  public static void addFunctions(SchemaPlus schema, @Nullable String functionName,
-      List<String> path, String className, @Nullable String methodName, boolean upCase) {
+  public static void addFunctions(SchemaPlus schema,
+      @Nullable String functionName, List<String> unusedPath,
+      String className, @Nullable String methodName, boolean upCase) {
     final Class<?> clazz;
     try {
       clazz = Class.forName(className);
@@ -517,7 +518,7 @@ public class ModelHandler {
   }
 
   public void visit(JsonMeasure jsonMeasure) {
-    assert latticeBuilder != null;
+    requireNonNull(latticeBuilder, "latticeBuilder");
     final boolean distinct = false; // no distinct field in JsonMeasure.yet
     final Lattice.Measure measure =
         latticeBuilder.resolveMeasure(jsonMeasure.agg, distinct,
diff --git a/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java b/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java
index 15d4b977d5..d2ed0a57a7 100644
--- a/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java
+++ b/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java
@@ -36,20 +36,20 @@ import org.slf4j.Logger;
 
 import java.text.NumberFormat;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.regex.Pattern;
 
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Abstract base for implementations of the {@link RelOptPlanner} interface.
  */
@@ -93,7 +93,7 @@ public abstract class AbstractRelOptPlanner implements RelOptPlanner {
    */
   protected AbstractRelOptPlanner(RelOptCostFactory costFactory,
       @Nullable Context context) {
-    this.costFactory = Objects.requireNonNull(costFactory, "costFactory");
+    this.costFactory = requireNonNull(costFactory, "costFactory");
     if (context == null) {
       context = Contexts.empty();
     }
@@ -149,8 +149,7 @@ public abstract class AbstractRelOptPlanner implements RelOptPlanner {
 
   @Override public boolean addRule(RelOptRule rule) {
     // Check that there isn't a rule with the same description
-    final String description = rule.toString();
-    assert description != null;
+    final String description = requireNonNull(rule.toString());
 
     RelOptRule existingRule = mapDescToRule.put(description, rule);
     if (existingRule != null) {
@@ -444,7 +443,7 @@ public abstract class AbstractRelOptPlanner implements RelOptPlanner {
   /** Listener for counting the attempts of each rule. Only enabled under DEBUG level.*/
   private static class RuleAttemptsListener implements RelOptListener {
     private long beforeTimestamp;
-    private Map<String, Pair<Long, Long>> ruleAttempts;
+    private final Map<String, Pair<Long, Long>> ruleAttempts;
 
     RuleAttemptsListener() {
       ruleAttempts = new HashMap<>();
@@ -459,12 +458,10 @@ public abstract class AbstractRelOptPlanner implements RelOptPlanner {
       } else {
         long elapsed = (System.nanoTime() - this.beforeTimestamp) / 1000;
         String rule = event.getRuleCall().getRule().toString();
-        if (ruleAttempts.containsKey(rule)) {
-          Pair<Long, Long> p = ruleAttempts.get(rule);
-          ruleAttempts.put(rule, Pair.of(p.left + 1, p.right + elapsed));
-        } else {
-          ruleAttempts.put(rule, Pair.of(1L,  elapsed));
-        }
+        ruleAttempts.compute(rule, (k, p) ->
+            p == null
+                ? Pair.of(1L,  elapsed)
+                : Pair.of(p.left + 1, p.right + elapsed));
       }
     }
 
@@ -482,17 +479,16 @@ public abstract class AbstractRelOptPlanner implements RelOptPlanner {
       // then by rule name ascending.
       List<Map.Entry<String, Pair<Long, Long>>> list =
           new ArrayList<>(this.ruleAttempts.entrySet());
-      Collections.sort(list,
-          (left, right) -> {
-            int res = right.getValue().left.compareTo(left.getValue().left);
-            if (res == 0) {
-              res = right.getValue().right.compareTo(left.getValue().right);
-            }
-            if (res == 0) {
-              res = left.getKey().compareTo(right.getKey());
-            }
-            return res;
-          });
+      list.sort((left, right) -> {
+        int res = right.getValue().left.compareTo(left.getValue().left);
+        if (res == 0) {
+          res = right.getValue().right.compareTo(left.getValue().right);
+        }
+        if (res == 0) {
+          res = left.getKey().compareTo(right.getKey());
+        }
+        return res;
+      });
 
       // Print out rule attempts and time
       StringBuilder sb = new StringBuilder();
diff --git a/core/src/main/java/org/apache/calcite/plan/Contexts.java b/core/src/main/java/org/apache/calcite/plan/Contexts.java
index 13c8fc8e14..9ffc22c63c 100644
--- a/core/src/main/java/org/apache/calcite/plan/Contexts.java
+++ b/core/src/main/java/org/apache/calcite/plan/Contexts.java
@@ -24,7 +24,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Utilities for {@link Context}.
@@ -117,7 +118,7 @@ public class Contexts {
     final Object target;
 
     WrapContext(Object target) {
-      this.target = Objects.requireNonNull(target, "target");
+      this.target = requireNonNull(target, "target");
     }
 
     @Override public <T extends Object> @Nullable T unwrap(Class<T> clazz) {
@@ -140,7 +141,7 @@ public class Contexts {
     final ImmutableList<Context> contexts;
 
     ChainContext(ImmutableList<Context> contexts) {
-      this.contexts = Objects.requireNonNull(contexts, "contexts");
+      this.contexts = requireNonNull(contexts, "contexts");
       for (Context context : contexts) {
         assert !(context instanceof ChainContext) : "must be flat";
       }
diff --git a/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java b/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java
index a4fc5b70e3..1a0f840af0 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java
@@ -23,7 +23,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.Arrays;
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * A trait that consists of a list of traits, all of the same type.
@@ -42,7 +43,7 @@ class RelCompositeTrait<T extends RelMultipleTrait> implements RelTrait {
   // Must remain private. Does not copy the array.
   private RelCompositeTrait(RelTraitDef traitDef, T[] traits) {
     this.traitDef = traitDef;
-    this.traits = Objects.requireNonNull(traits, "traits");
+    this.traits = requireNonNull(traits, "traits");
     //noinspection unchecked
     assert Ordering.natural()
         .isStrictlyOrdered(Arrays.asList((Comparable[]) traits))
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptCluster.java b/core/src/main/java/org/apache/calcite/plan/RelOptCluster.java
index eaec60a401..a5c9d3395e 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptCluster.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptCluster.java
@@ -35,12 +35,13 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Objects;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Supplier;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * An environment for related relational expressions during the
  * optimization of a query.
@@ -87,8 +88,8 @@ public class RelOptCluster {
       Map<String, RelNode> mapCorrelToRel) {
     this.nextCorrel = nextCorrel;
     this.mapCorrelToRel = mapCorrelToRel;
-    this.planner = Objects.requireNonNull(planner, "planner");
-    this.typeFactory = Objects.requireNonNull(typeFactory, "typeFactory");
+    this.planner = requireNonNull(planner, "planner");
+    this.typeFactory = requireNonNull(typeFactory, "typeFactory");
     this.rexBuilder = rexBuilder;
     this.originalExpression = rexBuilder.makeLiteral("?");
 
@@ -228,7 +229,7 @@ public class RelOptCluster {
    * @param hintStrategies The specified hint strategies to override the default one(empty)
    */
   public void setHintStrategies(HintStrategyTable hintStrategies) {
-    Objects.requireNonNull(hintStrategies, "hintStrategies");
+    requireNonNull(hintStrategies, "hintStrategies");
     this.hintStrategies = hintStrategies;
   }
 
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptLattice.java b/core/src/main/java/org/apache/calcite/plan/RelOptLattice.java
index fd5286aa8c..e5d4988643 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptLattice.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptLattice.java
@@ -82,7 +82,10 @@ public class RelOptLattice {
     final MaterializationService service = MaterializationService.instance();
     boolean create = lattice.auto && config.createMaterializations();
     final CalciteSchema schema = starRelOptTable.unwrap(CalciteSchema.class);
-    assert schema != null : "Can't get CalciteSchema from " + starRelOptTable;
+    if (schema == null) {
+      throw new IllegalArgumentException("Can't get CalciteSchema from "
+          + starRelOptTable);
+    }
     return service.defineTile(lattice, groupSet, measureList, schema, create,
         false);
   }
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptMaterialization.java b/core/src/main/java/org/apache/calcite/plan/RelOptMaterialization.java
index 62e4df7649..6cc5569bc7 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptMaterialization.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptMaterialization.java
@@ -46,6 +46,8 @@ import java.util.Objects;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Records that a particular query is materialized by a particular table.
  */
@@ -61,11 +63,10 @@ public class RelOptMaterialization {
    */
   public RelOptMaterialization(RelNode tableRel, RelNode queryRel,
       @Nullable RelOptTable starRelOptTable, List<String> qualifiedTableName) {
+    this.queryRel = requireNonNull(queryRel, "queryRel");
     this.tableRel =
-        RelOptUtil.createCastRel(
-            Objects.requireNonNull(tableRel, "tableRel"),
-            Objects.requireNonNull(queryRel, "queryRel").getRowType(),
-            false);
+        RelOptUtil.createCastRel(requireNonNull(tableRel, "tableRel"),
+            queryRel.getRowType(), false);
     this.starRelOptTable = starRelOptTable;
     if (starRelOptTable == null) {
       this.starTable = null;
@@ -73,7 +74,6 @@ public class RelOptMaterialization {
       this.starTable = starRelOptTable.unwrapOrThrow(StarTable.class);
     }
     this.qualifiedTableName = qualifiedTableName;
-    this.queryRel = queryRel;
   }
 
   /**
@@ -125,7 +125,8 @@ public class RelOptMaterialization {
                   try {
                     match(left, right, join.getCluster());
                   } catch (Util.FoundOne e) {
-                    return (RelNode) Objects.requireNonNull(e.getNode(), "FoundOne.getNode");
+                    return (RelNode) requireNonNull(e.getNode(),
+                        "FoundOne.getNode");
                   }
                 }
               }
@@ -225,7 +226,7 @@ public class RelOptMaterialization {
         Mappings.@Nullable TargetMapping mapping, TableScan scan) {
       this.condition = condition;
       this.mapping = mapping;
-      this.scan = Objects.requireNonNull(scan, "scan");
+      this.scan = requireNonNull(scan, "scan");
     }
 
     static @Nullable ProjectFilterTable of(RelNode node) {
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptPredicateList.java b/core/src/main/java/org/apache/calcite/plan/RelOptPredicateList.java
index 0ce5fca94e..749018531d 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptPredicateList.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptPredicateList.java
@@ -29,7 +29,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.Collection;
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Predicates that are known to hold in the output of a particular relational
@@ -96,12 +97,13 @@ public class RelOptPredicateList {
       ImmutableList<RexNode> leftInferredPredicates,
       ImmutableList<RexNode> rightInferredPredicates,
       ImmutableMap<RexNode, RexNode> constantMap) {
-    this.pulledUpPredicates = Objects.requireNonNull(pulledUpPredicates, "pulledUpPredicates");
+    this.pulledUpPredicates =
+        requireNonNull(pulledUpPredicates, "pulledUpPredicates");
     this.leftInferredPredicates =
-        Objects.requireNonNull(leftInferredPredicates, "leftInferredPredicates");
+        requireNonNull(leftInferredPredicates, "leftInferredPredicates");
     this.rightInferredPredicates =
-        Objects.requireNonNull(rightInferredPredicates, "rightInferredPredicates");
-    this.constantMap = Objects.requireNonNull(constantMap, "constantMap");
+        requireNonNull(rightInferredPredicates, "rightInferredPredicates");
+    this.constantMap = requireNonNull(constantMap, "constantMap");
   }
 
   /** Creates a RelOptPredicateList with only pulled-up predicates, no inferred
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptQuery.java b/core/src/main/java/org/apache/calcite/plan/RelOptQuery.java
index 03efd0175f..c617e3fb0c 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptQuery.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptQuery.java
@@ -27,6 +27,8 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import static java.lang.Integer.parseInt;
+
 /**
  * A <code>RelOptQuery</code> represents a set of
  * {@link RelNode relational expressions} which derive from the same
@@ -83,7 +85,7 @@ public class RelOptQuery {
   @Deprecated // to be removed before 2.0
   public static int getCorrelOrdinal(String correlName) {
     assert correlName.startsWith(CORREL_PREFIX);
-    return Integer.parseInt(correlName.substring(CORREL_PREFIX.length()));
+    return parseInt(correlName.substring(CORREL_PREFIX.length()));
   }
 
   /**
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptRule.java b/core/src/main/java/org/apache/calcite/plan/RelOptRule.java
index 080b50f660..8a6a002fb4 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptRule.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptRule.java
@@ -31,9 +31,10 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 import java.util.function.Predicate;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A <code>RelOptRule</code> transforms an expression into another. It has a
  * list of {@link RelOptRuleOperand}s, which determine whether the rule can be
@@ -99,8 +100,9 @@ public abstract class RelOptRule {
    */
   protected RelOptRule(RelOptRuleOperand operand,
       RelBuilderFactory relBuilderFactory, @Nullable String description) {
-    this.operand = Objects.requireNonNull(operand, "operand");
-    this.relBuilderFactory = Objects.requireNonNull(relBuilderFactory, "relBuilderFactory");
+    this.operand = requireNonNull(operand, "operand");
+    this.relBuilderFactory =
+        requireNonNull(relBuilderFactory, "relBuilderFactory");
     if (description == null) {
       description = guessDescription(getClass().getName());
     }
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptRuleOperand.java b/core/src/main/java/org/apache/calcite/plan/RelOptRuleOperand.java
index 65d74c60f7..bfdd51abcf 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptRuleOperand.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptRuleOperand.java
@@ -29,6 +29,10 @@ import java.util.List;
 import java.util.Objects;
 import java.util.function.Predicate;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
+import static java.util.Objects.requireNonNull;
+
 /**
  * Operand that determines whether a {@link RelOptRule}
  * can be applied to a particular expression.
@@ -103,32 +107,30 @@ public class RelOptRuleOperand {
    * <a href="https://issues.apache.org/jira/browse/CALCITE-1166">[CALCITE-1166]
    * Disallow sub-classes of RelOptRuleOperand</a>. */
   @SuppressWarnings({"initialization.fields.uninitialized",
-      "initialization.invalid.field.write.initialized"})
+      "initialization.invalid.field.write.initialized", "unchecked"})
   <R extends RelNode> RelOptRuleOperand(
       Class<R> clazz,
       @Nullable RelTrait trait,
       Predicate<? super R> predicate,
       RelOptRuleOperandChildPolicy childPolicy,
       ImmutableList<RelOptRuleOperand> children) {
-    assert clazz != null;
+    this.clazz = requireNonNull(clazz, "clazz");
     switch (childPolicy) {
     case ANY:
       break;
     case LEAF:
-      assert children.size() == 0;
+      checkArgument(children.isEmpty());
       break;
     case UNORDERED:
       assert children.size() == 1;
       break;
     default:
-      assert children.size() > 0;
+      checkArgument(!children.isEmpty());
     }
-    this.childPolicy = childPolicy;
-    this.clazz = Objects.requireNonNull(clazz, "clazz");
+    this.childPolicy = requireNonNull(childPolicy, "childPolicy");
     this.trait = trait;
-    //noinspection unchecked
-    this.predicate = Objects.requireNonNull((Predicate) predicate);
-    this.children = children;
+    this.predicate = requireNonNull((Predicate<RelNode>) predicate);
+    this.children = requireNonNull(children, "children");
     for (RelOptRuleOperand child : this.children) {
       assert child.parent == null : "cannot re-use operands";
       child.parent = this;
@@ -241,7 +243,7 @@ public class RelOptRuleOperand {
     if (this == that) {
       s.append('*');
     }
-    if (children != null && !children.isEmpty()) {
+    if (!children.isEmpty()) {
       s.append('(');
       boolean first = true;
       for (RelOptRuleOperand child : children) {
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptSchema.java b/core/src/main/java/org/apache/calcite/plan/RelOptSchema.java
index 77527c2e7b..75ff4dbd3b 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptSchema.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptSchema.java
@@ -49,8 +49,8 @@ public interface RelOptSchema {
   RelDataTypeFactory getTypeFactory();
 
   /**
-   * Registers all of the rules supported by this schema. Only called by
+   * Registers all the rules supported by this schema. Only called by
    * {@link RelOptPlanner#registerSchema}.
    */
-  void registerRules(RelOptPlanner planner) throws Exception;
+  void registerRules(RelOptPlanner planner);
 }
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
index cb644ccf1d..76e37434ab 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
@@ -139,6 +139,8 @@ import java.util.TreeSet;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 import static org.apache.calcite.rel.type.RelDataTypeImpl.NON_NULLABLE_SUFFIX;
 
 import static java.util.Objects.requireNonNull;
@@ -267,11 +269,11 @@ public abstract class RelOptUtil {
   public static List<CorrelationId> getVariablesSetAndUsed(RelNode rel0,
       RelNode rel1) {
     Set<CorrelationId> set = getVariablesSet(rel0);
-    if (set.size() == 0) {
+    if (set.isEmpty()) {
       return ImmutableList.of();
     }
     Set<CorrelationId> used = getVariablesUsed(rel1);
-    if (used.size() == 0) {
+    if (used.isEmpty()) {
       return ImmutableList.of();
     }
     final List<CorrelationId> result = new ArrayList<>();
@@ -425,7 +427,7 @@ public abstract class RelOptUtil {
     String s = "Cannot add expression of different type to set:\n"
         + "set type is " + expectedRowType.getFullTypeString()
         + "\nexpression type is " + actualRowType.getFullTypeString()
-        + "\nset is " + equivalenceClass.toString()
+        + "\nset is " + equivalenceClass
         + "\nexpression is " + RelOptUtil.toString(newRel)
         + getFullTypeDifferenceString("rowtype of original rel", expectedRowType,
         "rowtype of new rel", actualRowType);
@@ -463,7 +465,7 @@ public abstract class RelOptUtil {
   @Experimental
   public static RelNode propagateRelHints(RelNode originalRel, RelNode equiv) {
     if (!(originalRel instanceof Hintable)
-        || ((Hintable) originalRel).getHints().size() == 0) {
+        || ((Hintable) originalRel).getHints().isEmpty()) {
       return equiv;
     }
     final RelShuttle shuttle =
@@ -523,7 +525,7 @@ public abstract class RelOptUtil {
 
     if (originalRel instanceof Hintable
         && newRel instanceof Hintable
-        && ((Hintable) originalRel).getHints().size() > 0) {
+        && !((Hintable) originalRel).getHints().isEmpty()) {
       final List<RelHint> hints = ((Hintable) originalRel).getHints();
       if (filterHints) {
         HintStrategyTable hintStrategies = originalRel.getCluster().getHintStrategies();
@@ -625,7 +627,7 @@ public abstract class RelOptUtil {
     assert extraExpr == null || extraName != null;
     RelNode ret = seekRel;
 
-    if ((conditions != null) && (conditions.size() > 0)) {
+    if (conditions != null && !conditions.isEmpty()) {
       RexNode conditionExp =
           RexUtil.composeConjunction(
               cluster.getRexBuilder(), conditions, true);
@@ -821,7 +823,7 @@ public abstract class RelOptUtil {
   @Deprecated // to be removed before 2.0
   public static RelNode createNullFilter(
       RelNode rel,
-      Integer[] fieldOrdinals) {
+      Integer @Nullable [] fieldOrdinals) {
     RexNode condition = null;
     final RexBuilder rexBuilder = rel.getCluster().getRexBuilder();
     RelDataType rowType = rel.getRowType();
@@ -913,7 +915,7 @@ public abstract class RelOptUtil {
       RelDataType castRowType,
       boolean rename,
       RelFactories.ProjectFactory projectFactory) {
-    assert projectFactory != null;
+    requireNonNull(projectFactory, "projectFactory");
     RelDataType rowType = rel.getRowType();
     if (areRowTypesEqual(rowType, castRowType, rename)) {
       // nothing to do
@@ -963,8 +965,7 @@ public abstract class RelOptUtil {
   /** Gets all fields in an aggregate. */
   public static Set<Integer> getAllFields2(ImmutableBitSet groupSet,
       List<AggregateCall> aggCallList) {
-    final Set<Integer> allFields = new TreeSet<>();
-    allFields.addAll(groupSet.asList());
+    final Set<Integer> allFields = new TreeSet<>(groupSet.asList());
     for (AggregateCall aggregateCall : aggCallList) {
       allFields.addAll(aggregateCall.getArgList());
       if (aggregateCall.filterArg >= 0) {
@@ -1137,7 +1138,7 @@ public abstract class RelOptUtil {
         rightKeys,
         filterNulls,
         nonEquiList);
-    return nonEquiList.size() == 0;
+    return nonEquiList.isEmpty();
   }
 
   /**
@@ -2127,7 +2128,7 @@ public abstract class RelOptUtil {
       SqlExplainLevel detailLevel) {
     StringWriter sw = new StringWriter();
     PrintWriter pw = new PrintWriter(sw);
-    if (!header.equals("")) {
+    if (!header.isEmpty()) {
       pw.println(header);
     }
     RelWriter planWriter;
@@ -2357,8 +2358,8 @@ public abstract class RelOptUtil {
 
     // The result of IS DISTINCT FROM is NOT NULL because it can
     // only return TRUE or FALSE.
-    assert ret != null;
-    assert !ret.getType().isNullable();
+    requireNonNull(ret, "ret");
+    checkArgument(!ret.getType().isNullable());
 
     return ret;
   }
@@ -3702,7 +3703,7 @@ public abstract class RelOptUtil {
     return !calc.containsOver();
   }
 
-  /** Predicate for if a {@link Filter} does not windowed aggregates. */
+  /** Predicate for if a {@link Filter} does not contain windowed aggregates. */
   public static boolean notContainsWindowedAgg(Filter filter) {
     return !filter.containsOver();
   }
@@ -4015,10 +4016,7 @@ public abstract class RelOptUtil {
     if (before == after) {
       return;
     }
-    for (int i = 0; i < operands.size(); i++) {
-      RexNode node = operands.get(i);
-      operands.set(i, RexUtil.shift(node, before, after - before));
-    }
+    operands.replaceAll(e -> RexUtil.shift(e, before, after - before));
   }
 
   /**
@@ -4174,7 +4172,7 @@ public abstract class RelOptUtil {
      */
     private RelNode visitHintable(RelNode node) {
       final List<RelHint> topHints = ((Hintable) node).getHints();
-      final boolean hasHints = topHints != null && topHints.size() > 0;
+      final boolean hasHints = !topHints.isEmpty();
       final boolean hasQueryHints = hasHints && !(node instanceof TableScan);
       if (hasQueryHints) {
         inheritPaths.push(Pair.of(topHints, new ArrayDeque<>()));
@@ -4188,7 +4186,7 @@ public abstract class RelOptUtil {
 
     private RelNode attachHints(RelNode original) {
       assert original instanceof Hintable;
-      if (inheritPaths.size() > 0) {
+      if (!inheritPaths.isEmpty()) {
         final List<RelHint> hints = inheritPaths.stream()
             .sorted(Comparator.comparingInt(o -> o.right.size()))
             .map(path -> copyWithInheritPath(path.left, path.right))
@@ -4197,7 +4195,7 @@ public abstract class RelOptUtil {
               return acc;
             });
         final List<RelHint> filteredHints = hintStrategies.apply(hints, original);
-        if (filteredHints.size() > 0) {
+        if (!filteredHints.isEmpty()) {
           return ((Hintable) original).attachHints(filteredHints);
         }
       }
@@ -4303,7 +4301,7 @@ public abstract class RelOptUtil {
      */
     private RelNode visitHintable(RelNode node) {
       final List<RelHint> topHints = ((Hintable) node).getHints();
-      final boolean hasHints = topHints != null && topHints.size() > 0;
+      final boolean hasHints = !topHints.isEmpty();
       if (hasHints) {
         // This node is definitely not created by the planner, returns early.
         return node;
@@ -4321,7 +4319,7 @@ public abstract class RelOptUtil {
           .map(hint -> copyWithAppendPath(hint, appendPath))
           .collect(Collectors.toList());
       final List<RelHint> filteredHints = hintStrategies.apply(hints, original);
-      if (filteredHints.size() > 0) {
+      if (!filteredHints.isEmpty()) {
         return ((Hintable) original).attachHints(filteredHints);
       }
       return original;
@@ -4329,7 +4327,7 @@ public abstract class RelOptUtil {
 
     private static RelHint copyWithAppendPath(RelHint hint,
         List<Integer> appendPaths) {
-      if (appendPaths.size() == 0) {
+      if (appendPaths.isEmpty()) {
         return hint;
       } else {
         List<Integer> newPath = new ArrayList<>(hint.inheritPath);
@@ -4366,14 +4364,14 @@ public abstract class RelOptUtil {
     }
 
     private static RelNode resetHints(Hintable hintable) {
-      if (hintable.getHints().size() > 0) {
-        final List<RelHint> resetHints = hintable.getHints().stream()
-            .filter(hint -> hint.inheritPath.size() == 0)
-            .collect(Collectors.toList());
-        return hintable.withHints(resetHints);
-      } else {
+      if (hintable.getHints().isEmpty()) {
         return (RelNode) hintable;
       }
+      final List<RelHint> resetHints =
+          hintable.getHints().stream()
+              .filter(hint -> hint.inheritPath.isEmpty())
+              .collect(Collectors.toList());
+      return hintable.withHints(resetHints);
     }
   }
 
diff --git a/core/src/main/java/org/apache/calcite/plan/RelRule.java b/core/src/main/java/org/apache/calcite/plan/RelRule.java
index cc1f98da5e..4e7f655d37 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelRule.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelRule.java
@@ -28,11 +28,12 @@ import org.immutables.value.Value;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
-import java.util.Objects;
 import java.util.function.BiConsumer;
 import java.util.function.Function;
 import java.util.function.Predicate;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Rule that is parameterized via a configuration.
  *
@@ -235,8 +236,7 @@ public abstract class RelRule<C extends RelRule.Config> extends RelOptRule {
 
     static RelOptRuleOperand operand(OperandTransform transform) {
       final OperandBuilderImpl b = new OperandBuilderImpl();
-      final Done done = transform.apply(b);
-      Objects.requireNonNull(done, "done");
+      requireNonNull(transform.apply(b), "done");
       if (b.operands.size() != 1) {
         throw new IllegalArgumentException("operand supplier must call one of "
             + "the following methods: operand or exactly");
@@ -266,12 +266,12 @@ public abstract class RelRule<C extends RelRule.Config> extends RelOptRule {
     private Predicate<? super R> predicate = r -> true;
 
     OperandDetailBuilderImpl(OperandBuilderImpl parent, Class<R> relClass) {
-      this.parent = Objects.requireNonNull(parent, "parent");
-      this.relClass = Objects.requireNonNull(relClass, "relClass");
+      this.parent = requireNonNull(parent, "parent");
+      this.relClass = requireNonNull(relClass, "relClass");
     }
 
     @Override public OperandDetailBuilderImpl<R> trait(RelTrait trait) {
-      this.trait = Objects.requireNonNull(trait, "trait");
+      this.trait = requireNonNull(trait, "trait");
       return this;
     }
 
@@ -304,14 +304,14 @@ public abstract class RelRule<C extends RelRule.Config> extends RelOptRule {
 
     @Override public Done oneInput(OperandTransform transform) {
       final Done done = transform.apply(inputBuilder);
-      Objects.requireNonNull(done, "done");
+      requireNonNull(done, "done");
       return done(RelOptRuleOperandChildPolicy.SOME);
     }
 
     @Override public Done inputs(OperandTransform... transforms) {
       for (OperandTransform transform : transforms) {
         final Done done = transform.apply(inputBuilder);
-        Objects.requireNonNull(done, "done");
+        requireNonNull(done, "done");
       }
       return done(RelOptRuleOperandChildPolicy.SOME);
     }
@@ -319,7 +319,7 @@ public abstract class RelRule<C extends RelRule.Config> extends RelOptRule {
     @Override public Done unorderedInputs(OperandTransform... transforms) {
       for (OperandTransform transform : transforms) {
         final Done done = transform.apply(inputBuilder);
-        Objects.requireNonNull(done, "done");
+        requireNonNull(done, "done");
       }
       return done(RelOptRuleOperandChildPolicy.UNORDERED);
     }
diff --git a/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java b/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java
index 9e7e3d5a9f..b91b660752 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java
@@ -33,6 +33,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.function.Supplier;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * RelTraitSet represents an ordered set of {@link RelTrait}s.
  */
@@ -638,7 +640,7 @@ public final class RelTraitSet extends AbstractList<RelTrait> {
       return replace(i, trait);
     }
     final RelTrait canonizedTrait = canonize(trait);
-    assert canonizedTrait != null;
+    requireNonNull(canonizedTrait, "canonizedTrait");
     RelTrait[] newTraits = new RelTrait[traits.length + 1];
     System.arraycopy(traits, 0, newTraits, 0, traits.length);
     newTraits[traits.length] = canonizedTrait;
diff --git a/core/src/main/java/org/apache/calcite/plan/RexImplicationChecker.java b/core/src/main/java/org/apache/calcite/plan/RexImplicationChecker.java
index f5230dd091..1b07880623 100644
--- a/core/src/main/java/org/apache/calcite/plan/RexImplicationChecker.java
+++ b/core/src/main/java/org/apache/calcite/plan/RexImplicationChecker.java
@@ -219,7 +219,7 @@ public class RexImplicationChecker {
         : firstUsageFinder.usageMap.entrySet()) {
       ImmutableSet.Builder<Pair<RexInputRef, @Nullable RexNode>> usageBuilder =
           ImmutableSet.builder();
-      if (entry.getValue().usageList.size() > 0) {
+      if (!entry.getValue().usageList.isEmpty()) {
         entry.getValue().usageList.rightList().forEach(v ->
             usageBuilder.add(Pair.of(entry.getKey(), v)));
         usagesBuilder.add(usageBuilder.build());
diff --git a/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java b/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
index b8acb6c991..e8e4a46541 100644
--- a/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
+++ b/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
@@ -425,10 +425,7 @@ public class SubstitutionVisitor {
         new HashSet<>(RexUtil.strings(RelOptUtil.conjunctions(condition)));
     final Set<String> targetDisjunctions =
         new HashSet<>(RexUtil.strings(RelOptUtil.conjunctions(target)));
-    if (conditionDisjunctions.equals(targetDisjunctions)) {
-      return true;
-    }
-    return false;
+    return conditionDisjunctions.equals(targetDisjunctions);
   }
 
   /**
@@ -615,13 +612,15 @@ public class SubstitutionVisitor {
                 if (targetDescendant == target) {
                   // A real substitution happens. We purge the attempted
                   // replacement list and add them into substitution list.
-                  // Meanwhile we stop matching the descendants and jump
+                  // Meanwhile, we stop matching the descendants and jump
                   // to the next subtree in pre-order traversal.
                   if (!target.equals(replacement)) {
                     Replacement r =
                         replace(query.getInput(), target, replacement.clone());
-                    assert r != null
-                        : rule + "should have returned a result containing the target.";
+                    if (r == null) {
+                      throw new AssertionError(rule + " should have returned "
+                          + "a result containing the target.");
+                    }
                     attempted.add(r);
                   }
                   substitutions.add(ImmutableList.copyOf(attempted));
@@ -795,7 +794,7 @@ public class SubstitutionVisitor {
         }
       }
     } else {
-      assert queryParent != null;
+      requireNonNull(queryParent, "queryParent");
       for (UnifyRule rule : applicableRules(queryParent, target)) {
         final UnifyResult x = apply(rule, queryParent, target);
         if (x != null) {
@@ -1760,16 +1759,15 @@ public class SubstitutionVisitor {
   /** Explain filtering condition and projections from MutableCalc. */
   public static Pair<RexNode, List<RexNode>> explainCalc(MutableCalc calc) {
     final RexShuttle shuttle = getExpandShuttle(calc.program);
-    final RexNode condition = shuttle.apply(calc.program.getCondition());
-    final List<RexNode> projects = new ArrayList<>();
-    for (RexNode rex : shuttle.apply(calc.program.getProjectList())) {
-      projects.add(rex);
-    }
-    if (condition == null) {
-      return Pair.of(calc.cluster.getRexBuilder().makeLiteral(true), projects);
+    final RexNode condition;
+    if (calc.program.getCondition() == null) {
+      condition = calc.cluster.getRexBuilder().makeLiteral(true);
     } else {
-      return Pair.of(condition, projects);
+      condition = calc.program.getCondition().accept(shuttle);
     }
+    final List<RexNode> projects =
+        ImmutableList.copyOf(shuttle.apply(calc.program.getProjectList()));
+    return Pair.of(condition, projects);
   }
 
   /**
@@ -2029,7 +2027,7 @@ public class SubstitutionVisitor {
       newArgList.add(newArgIndex);
     }
     final boolean isAllowBuild;
-    if (newArgList.size() == 0) {
+    if (newArgList.isEmpty()) {
       // Size of agg-call's args is empty, we stop to build a new agg-call,
       // eg: count(1) or count(*).
       isAllowBuild = false;
@@ -2037,7 +2035,8 @@ public class SubstitutionVisitor {
       // Args of agg-call is distinct, we can build a new agg-call.
       isAllowBuild = true;
     } else if (aggregation.getDistinctOptionality() == Optionality.IGNORED) {
-      // If attribute of agg-call's distinct could be ignore, we can build a new agg-call.
+      // If attribute of agg-call's distinct could be ignored,
+      // we can build a new agg-call.
       isAllowBuild = true;
     } else {
       isAllowBuild = false;
@@ -2159,34 +2158,29 @@ public class SubstitutionVisitor {
         && !isCalcStrong(qInput0Explained)) {
       return false;
     }
-    if (qInput1Explained != null
-        && joinType.generatesNullsOn(1)
-        && !isCalcStrong(qInput1Explained)) {
-      return false;
-    }
-    return true;
+    return qInput1Explained == null
+        || !joinType.generatesNullsOn(1)
+        || isCalcStrong(qInput1Explained);
   }
 
   /** Determines if all projects are strong and the condition is always true. */
   private static boolean isCalcStrong(Pair<RexNode, List<RexNode>> inputExplained) {
-    final RexNode cond = requireNonNull(inputExplained.left, "condition");
-    final List<RexNode> projs = requireNonNull(inputExplained.right, "projects");
+    final RexNode cond = inputExplained.left;
+    final List<RexNode> projs = inputExplained.right;
     return cond.isAlwaysTrue() && projs.stream().allMatch(STRONG::isNull);
   }
 
-  /**
-
-   */
-
   /**
    * Generates project expressions by shifting and adjusting the nullability of expressions
    * based on the provided join targets and inputs.
    *
    * <p>Used in the Join rewrite to pull up the calc in query
-   * to the join in mv to ensure operator equivalence. (Already make sure that pull up is valid).
-   * Working in rules: {@link JoinOnLeftCalcToJoinUnifyRule} <br/>
-   * {@link JoinOnRightCalcToJoinUnifyRule} <br/>
-   * {@link JoinOnCalcsToJoinUnifyRule} <br/>
+   * to the join in mv to ensure operator equivalence.
+   * (Already make sure that pull up is valid).
+   *
+   * <p>Working in rules: {@link JoinOnLeftCalcToJoinUnifyRule},
+   * {@link JoinOnRightCalcToJoinUnifyRule},
+   * {@link JoinOnCalcsToJoinUnifyRule}.
    *
    * @param query MutableRel of query
    * @param target MutableRel of target
@@ -2402,15 +2396,16 @@ public class SubstitutionVisitor {
       this.ordinal = ordinal;
     }
 
-    @Override public boolean matches(SubstitutionVisitor visitor, MutableRel rel) {
+    @Override public boolean matches(SubstitutionVisitor visitor,
+        MutableRel rel) {
       final MutableRel rel0 = visitor.slots[ordinal];
-      assert rel0 != null : "QueryOperand should have been called first";
+      requireNonNull(rel0, "QueryOperand should have been called first");
       return rel0 == rel || visitor.equivalents.get(rel0).contains(rel);
     }
 
     @Override public boolean isWeaker(SubstitutionVisitor visitor, MutableRel rel) {
       final MutableRel rel0 = visitor.slots[ordinal];
-      assert rel0 != null : "QueryOperand should have been called first";
+      requireNonNull(rel0, "QueryOperand should have been called first");
       return visitor.isWeaker(rel0, rel);
     }
   }
diff --git a/core/src/main/java/org/apache/calcite/plan/hep/HepRuleCall.java b/core/src/main/java/org/apache/calcite/plan/hep/HepRuleCall.java
index 3ed3822b41..bc2e3db8a8 100644
--- a/core/src/main/java/org/apache/calcite/plan/hep/HepRuleCall.java
+++ b/core/src/main/java/org/apache/calcite/plan/hep/HepRuleCall.java
@@ -37,7 +37,7 @@ import java.util.Map;
 public class HepRuleCall extends RelOptRuleCall {
   //~ Instance fields --------------------------------------------------------
 
-  private List<RelNode> results;
+  private final List<RelNode> results = new ArrayList<>();
 
   //~ Constructors -----------------------------------------------------------
 
@@ -48,8 +48,6 @@ public class HepRuleCall extends RelOptRuleCall {
       Map<RelNode, List<RelNode>> nodeChildren,
       @Nullable List<RelNode> parents) {
     super(planner, operand, rels, nodeChildren, parents);
-
-    results = new ArrayList<>();
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/visualizer/InputExcludedRelWriter.java b/core/src/main/java/org/apache/calcite/plan/visualizer/InputExcludedRelWriter.java
index 5608da8fed..c3a0f894ab 100644
--- a/core/src/main/java/org/apache/calcite/plan/visualizer/InputExcludedRelWriter.java
+++ b/core/src/main/java/org/apache/calcite/plan/visualizer/InputExcludedRelWriter.java
@@ -48,10 +48,7 @@ class InputExcludedRelWriter implements RelWriter {
 
 
   @Override public void explain(RelNode rel, List<Pair<String, @Nullable Object>> valueList) {
-    valueList.forEach(pair -> {
-      assert pair.left != null;
-      this.values.put(pair.left, pair.right);
-    });
+    valueList.forEach(pair -> values.put(pair.left, pair.right));
   }
 
   @Override public SqlExplainLevel getDetailLevel() {
diff --git a/core/src/main/java/org/apache/calcite/plan/visualizer/NodeUpdateHelper.java b/core/src/main/java/org/apache/calcite/plan/visualizer/NodeUpdateHelper.java
index cdbbb9dd4f..4b4e56d784 100644
--- a/core/src/main/java/org/apache/calcite/plan/visualizer/NodeUpdateHelper.java
+++ b/core/src/main/java/org/apache/calcite/plan/visualizer/NodeUpdateHelper.java
@@ -62,7 +62,7 @@ class NodeUpdateHelper {
     }
 
     if (newValue instanceof List
-        && ((List<?>) newValue).size() == 0
+        && ((List<?>) newValue).isEmpty()
         && !update.containsKey(attr)) {
       return;
     }
diff --git a/core/src/main/java/org/apache/calcite/plan/visualizer/RuleMatchVisualizer.java b/core/src/main/java/org/apache/calcite/plan/visualizer/RuleMatchVisualizer.java
index 7aa703dca6..18f4719b66 100644
--- a/core/src/main/java/org/apache/calcite/plan/visualizer/RuleMatchVisualizer.java
+++ b/core/src/main/java/org/apache/calcite/plan/visualizer/RuleMatchVisualizer.java
@@ -51,13 +51,14 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Set;
 
 import static com.google.common.collect.ImmutableList.toImmutableList;
 
 import static org.apache.calcite.util.Util.transform;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * This is a tool to visualize the rule match process of a RelOptPlanner.
  *
@@ -82,7 +83,9 @@ public class RuleMatchVisualizer implements RelOptListener {
 
   // default HTML template can be edited at
   // core/src/main/resources/org/apache/calcite/plan/visualizer/viz-template.html
-  private final String templateDirectory = "org/apache/calcite/plan/visualizer";
+  private static final String TEMPLATE_DIRECTORY =
+      "org/apache/calcite/plan/visualizer";
+
   private final @Nullable String outputDirectory;
   private final @Nullable String outputSuffix;
 
@@ -108,8 +111,8 @@ public class RuleMatchVisualizer implements RelOptListener {
   public RuleMatchVisualizer(
       String outputDirectory,
       String outputSuffix) {
-    this.outputDirectory = Objects.requireNonNull(outputDirectory, "outputDirectory");
-    this.outputSuffix = Objects.requireNonNull(outputSuffix, "outputSuffix");
+    this.outputDirectory = requireNonNull(outputDirectory, "outputDirectory");
+    this.outputSuffix = requireNonNull(outputSuffix, "outputSuffix");
   }
 
   /**
@@ -148,9 +151,8 @@ public class RuleMatchVisualizer implements RelOptListener {
   @Override public void ruleAttempted(RuleAttemptedEvent event) {
     // HepPlanner compatibility
     if (!initialized) {
-      assert planner != null;
-      RelNode root = planner.getRoot();
-      assert root != null;
+      requireNonNull(planner, "planner");
+      RelNode root = requireNonNull(planner.getRoot());
       initialized = true;
       updateInitialPlan(root);
     }
@@ -182,9 +184,8 @@ public class RuleMatchVisualizer implements RelOptListener {
 
   @Override public void relChosen(RelChosenEvent event) {
     if (event.getRel() == null) {
-      assert this.planner != null;
-      RelNode root = this.planner.getRoot();
-      assert root != null;
+      requireNonNull(planner, "planner");
+      RelNode root = requireNonNull(planner.getRoot());
       updateFinalPlan(root);
       this.addStep(FINAL, null);
       this.writeToFile();
@@ -246,8 +247,7 @@ public class RuleMatchVisualizer implements RelOptListener {
   }
 
   @Override public void relEquivalenceFound(RelEquivalenceEvent event) {
-    RelNode rel = event.getRel();
-    assert rel != null;
+    final RelNode rel = requireNonNull(event.getRel());
     Object eqClass = event.getEquivalenceClass();
     if (eqClass instanceof String) {
       String eqClassStr = (String) eqClass;
@@ -296,8 +296,7 @@ public class RuleMatchVisualizer implements RelOptListener {
   private void updateNodeInfo(final RelNode rel, final boolean isLastStep) {
     NodeUpdateHelper helper = registerRelNode(rel);
     if (this.includeIntermediateCosts || isLastStep) {
-      RelOptPlanner planner = this.planner;
-      assert planner != null;
+      final RelOptPlanner planner = requireNonNull(this.planner);
       RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
       RelOptCost cost = planner.getCost(rel, mq);
       Double rowCount = mq.getRowCount(rel);
@@ -384,11 +383,11 @@ public class RuleMatchVisualizer implements RelOptListener {
     }
 
     try {
-      String templatePath = Paths.get(templateDirectory).resolve("viz-template.html").toString();
-      ClassLoader cl = getClass().getClassLoader();
-      assert cl != null;
-      InputStream resourceAsStream = cl.getResourceAsStream(templatePath);
-      assert resourceAsStream != null;
+      final String templatePath =
+          Paths.get(TEMPLATE_DIRECTORY).resolve("viz-template.html").toString();
+      final ClassLoader cl = requireNonNull(getClass().getClassLoader());
+      final InputStream resourceAsStream =
+          requireNonNull(cl.getResourceAsStream(templatePath));
       String htmlTemplate = IOUtils.toString(resourceAsStream, StandardCharsets.UTF_8);
 
       String htmlFileName = "planner-viz" + outputSuffix + ".html";
diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/IterativeRuleDriver.java b/core/src/main/java/org/apache/calcite/plan/volcano/IterativeRuleDriver.java
index 9aea576e95..c738fdd4ff 100644
--- a/core/src/main/java/org/apache/calcite/plan/volcano/IterativeRuleDriver.java
+++ b/core/src/main/java/org/apache/calcite/plan/volcano/IterativeRuleDriver.java
@@ -21,6 +21,8 @@ import org.apache.calcite.util.trace.CalciteTrace;
 
 import org.slf4j.Logger;
 
+import static java.util.Objects.requireNonNull;
+
 /***
  * The algorithm executes repeatedly. The exact rules
  * that may be fired varies.
@@ -46,7 +48,7 @@ class IterativeRuleDriver implements RuleDriver {
 
   @Override public void drive() {
     while (true) {
-      assert planner.root != null : "RelSubset must not be null at this point";
+      requireNonNull(planner.root, "RelSubset must not be null at this point");
       LOGGER.debug("Best cost before rule match: {}", planner.root.bestCost);
 
       VolcanoRuleMatch match = ruleQueue.popMatch();
diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/RelSet.java b/core/src/main/java/org/apache/calcite/plan/volcano/RelSet.java
index 6d0890e869..d715f37d27 100644
--- a/core/src/main/java/org/apache/calcite/plan/volcano/RelSet.java
+++ b/core/src/main/java/org/apache/calcite/plan/volcano/RelSet.java
@@ -136,7 +136,8 @@ class RelSet {
         continue;
       }
       for (RelNode child : node.getInputs()) {
-        RelSet childSet = planner.equivRoot(((RelSubset) child).getSet());
+        RelSet childSet =
+            VolcanoPlanner.equivRoot(((RelSubset) child).getSet());
         if (childSet.id != this.id) {
           childSets.add(childSet);
         }
@@ -387,7 +388,7 @@ class RelSet {
         subset = getOrCreateSubset(cluster, otherTraits, true);
       }
 
-      assert subset != null;
+      requireNonNull(subset, "subset");
       if (subset.passThroughCache == null) {
         subset.passThroughCache = otherSubset.passThroughCache;
       } else if (otherSubset.passThroughCache != null) {
diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/RelSubset.java b/core/src/main/java/org/apache/calcite/plan/volcano/RelSubset.java
index 29b26adb36..8fa18de241 100644
--- a/core/src/main/java/org/apache/calcite/plan/volcano/RelSubset.java
+++ b/core/src/main/java/org/apache/calcite/plan/volcano/RelSubset.java
@@ -605,12 +605,12 @@ public class RelSubset extends AbstractRelNode {
    * with the cheapest implementation of the expression.
    */
   static class CheapestPlanReplacer {
-    VolcanoPlanner planner;
+    final VolcanoPlanner planner;
     final Map<Integer, RelNode> visited = new HashMap<>();
 
     CheapestPlanReplacer(VolcanoPlanner planner) {
       super();
-      this.planner = planner;
+      this.planner = requireNonNull(planner, "planner");
     }
 
     private static String traitDiff(RelTraitSet original, RelTraitSet desired) {
diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/TopDownRuleDriver.java b/core/src/main/java/org/apache/calcite/plan/volcano/TopDownRuleDriver.java
index 821c7e5335..8e25a8e45b 100644
--- a/core/src/main/java/org/apache/calcite/plan/volcano/TopDownRuleDriver.java
+++ b/core/src/main/java/org/apache/calcite/plan/volcano/TopDownRuleDriver.java
@@ -264,7 +264,7 @@ class TopDownRuleDriver implements RuleDriver {
    */
   private static class TaskDescriptor {
     private boolean first = true;
-    private StringBuilder builder = new StringBuilder();
+    private final StringBuilder builder = new StringBuilder();
 
     void log(Task task) {
       if (!LOGGER.isDebugEnabled()) {
@@ -308,7 +308,7 @@ class TopDownRuleDriver implements RuleDriver {
    */
   private class OptimizeGroup implements Task {
     private final RelSubset group;
-    private RelOptCost upperBound;
+    private final RelOptCost upperBound;
 
     OptimizeGroup(RelSubset group, RelOptCost upperBound) {
       this.group = group;
diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
index 80faf61d92..a5cf48e2af 100644
--- a/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
+++ b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
@@ -84,6 +84,8 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 
 import static java.util.Objects.requireNonNull;
@@ -201,7 +203,7 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
   /**
    * Extra roots for explorations.
    */
-  Set<RelSubset> explorationRoots = new HashSet<>();
+  final Set<RelSubset> explorationRoots = new HashSet<>();
 
   //~ Constructors -----------------------------------------------------------
 
@@ -310,8 +312,8 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
       return;
     }
 
-    assert root != null : "root";
-    assert originalRoot != null : "originalRoot";
+    requireNonNull(root, "root");
+    requireNonNull(originalRoot, "originalRoot");
 
     // Register rels using materialized views.
     final List<Pair<RelNode, List<RelOptMaterialization>>> materializationUses =
@@ -362,11 +364,10 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
    * registered
    */
   public @Nullable RelSet getSet(RelNode rel) {
-    assert rel != null : "pre: rel != null";
+    requireNonNull(rel, "rel");
     final RelSubset subset = getSubset(rel);
     if (subset != null) {
-      assert subset.set != null;
-      return subset.set;
+      return requireNonNull(subset.set, "subset.set");
     }
     return null;
   }
@@ -517,7 +518,7 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
    * query
    */
   @Override public RelNode findBestExp() {
-    assert root != null : "'root' must not be null";
+    requireNonNull(root, "root");
     ensureRootConverters();
     registerMaterializations();
 
@@ -719,7 +720,7 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
   }
 
   @Override public @Nullable RelOptCost getCost(RelNode rel, RelMetadataQuery mq) {
-    assert rel != null : "pre-condition: rel != null";
+    requireNonNull(rel, "rel");
     if (rel instanceof RelSubset) {
       return ((RelSubset) rel).bestCost;
     }
@@ -752,7 +753,7 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
    * @return Subset it belongs to, or null if it is not registered
    */
   public @Nullable RelSubset getSubset(RelNode rel) {
-    assert rel != null : "pre: rel != null";
+    requireNonNull(rel, "rel");
     if (rel instanceof RelSubset) {
       return (RelSubset) rel;
     } else {
@@ -921,10 +922,10 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
         // Remove rel from its subset. (This may leave the subset
         // empty, but if so, that will be dealt with when the sets
         // get merged.)
-        final RelSubset subset = mapRel2Subset.put(rel, equivRelSubset);
-        assert subset != null;
+        final RelSubset subset =
+            requireNonNull(mapRel2Subset.put(rel, equivRelSubset));
         boolean existed = subset.set.rels.remove(rel);
-        assert existed : "rel was not known to its set";
+        checkArgument(existed, "rel was not known to its set");
         final RelSubset equivSubset = getSubsetNonNull(equivRel);
         for (RelSubset s : subset.set.subsets) {
           if (s.best == rel) {
@@ -1269,8 +1270,8 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
     // Now is a good time to ensure that the relational expression
     // implements the interface required by its calling convention.
     final RelTraitSet traits = rel.getTraitSet();
-    final Convention convention = traits.getTrait(ConventionTraitDef.INSTANCE);
-    assert convention != null;
+    final Convention convention =
+        requireNonNull(traits.getTrait(ConventionTraitDef.INSTANCE));
     if (!convention.getInterface().isInstance(rel)
         && !(rel instanceof Converter)) {
       throw new AssertionError("Relational expression " + rel
diff --git a/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java b/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
index 1e4896a2db..170bb1d1c0 100644
--- a/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
+++ b/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
@@ -73,12 +73,13 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.NavigableSet;
-import java.util.Objects;
 import java.util.function.Function;
 import java.util.function.Predicate;
 
 import static com.google.common.collect.ImmutableList.toImmutableList;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Implementation of {@link org.apache.calcite.prepare.Prepare.CatalogReader}
  * and also {@link org.apache.calcite.sql.SqlOperatorTable} based on tables and
@@ -92,9 +93,10 @@ public class CalciteCatalogReader implements Prepare.CatalogReader {
   protected final CalciteConnectionConfig config;
 
   public CalciteCatalogReader(CalciteSchema rootSchema,
-      List<String> defaultSchema, RelDataTypeFactory typeFactory, CalciteConnectionConfig config) {
-    this(rootSchema, SqlNameMatchers.withCaseSensitive(config != null && config.caseSensitive()),
-        ImmutableList.of(Objects.requireNonNull(defaultSchema, "defaultSchema"),
+      List<String> defaultSchema, RelDataTypeFactory typeFactory,
+      CalciteConnectionConfig config) {
+    this(rootSchema, SqlNameMatchers.withCaseSensitive(config.caseSensitive()),
+        ImmutableList.of(ImmutableList.copyOf(defaultSchema),
             ImmutableList.of()),
         typeFactory, config);
   }
@@ -102,7 +104,7 @@ public class CalciteCatalogReader implements Prepare.CatalogReader {
   protected CalciteCatalogReader(CalciteSchema rootSchema,
       SqlNameMatcher nameMatcher, List<List<String>> schemaPaths,
       RelDataTypeFactory typeFactory, CalciteConnectionConfig config) {
-    this.rootSchema = Objects.requireNonNull(rootSchema, "rootSchema");
+    this.rootSchema = requireNonNull(rootSchema, "rootSchema");
     this.nameMatcher = nameMatcher;
     this.schemaPaths =
         Util.immutableCopy(Util.isDistinct(schemaPaths)
diff --git a/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java b/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java
index ebce7c15d3..4f71fd5af5 100644
--- a/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java
+++ b/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java
@@ -341,7 +341,7 @@ public class CalcitePrepareImpl implements CalcitePrepare {
     for (RelDataTypeField field : targetRowType.getFieldList()) {
       final int x = columnMapping.indexOf(field.getIndex());
       if (x >= 0) {
-        assert Util.skip(columnMapping, x + 1).indexOf(field.getIndex()) < 0
+        assert !Util.skip(columnMapping, x + 1).contains(field.getIndex())
             : "column projected more than once; should have checked above";
         continue; // target column is projected
       }
@@ -689,7 +689,7 @@ public class CalcitePrepareImpl implements CalcitePrepare {
           preparingStmt.prepareQueryable(query.queryable, x);
       statementType = getStatementType(preparedResult);
     } else {
-      assert query.rel != null;
+      requireNonNull(query.rel);
       x = query.rel.getRowType();
       preparedResult = preparingStmt.prepareRel(query.rel);
       statementType = getStatementType(preparedResult);
@@ -822,8 +822,8 @@ public class CalcitePrepareImpl implements CalcitePrepare {
       final ColumnMetaData.AvaticaType componentType =
           avaticaType(typeFactory, type.getComponentType(), null);
       final Type clazz = typeFactory.getJavaClass(type.getComponentType());
-      final ColumnMetaData.Rep rep = ColumnMetaData.Rep.of(clazz);
-      assert rep != null;
+      final ColumnMetaData.Rep rep =
+          requireNonNull(ColumnMetaData.Rep.of(clazz));
       return ColumnMetaData.array(componentType, typeName, rep);
     } else {
       int typeOrdinal = getTypeOrdinal(type);
@@ -842,8 +842,8 @@ public class CalcitePrepareImpl implements CalcitePrepare {
       default:
         final Type clazz =
             typeFactory.getJavaClass(Util.first(fieldType, type));
-        final ColumnMetaData.Rep rep = ColumnMetaData.Rep.of(clazz);
-        assert rep != null;
+        final ColumnMetaData.Rep rep =
+            requireNonNull(ColumnMetaData.Rep.of(clazz));
         return ColumnMetaData.scalar(typeOrdinal, typeName, rep);
       }
     }
diff --git a/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
index 6792a87de8..ff2903047d 100644
--- a/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
+++ b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
@@ -92,10 +92,10 @@ public class PlannerImpl implements Planner, ViewExpander {
   private boolean open;
 
   // set in STATE_2_READY
-  private @Nullable SchemaPlus defaultSchema;
+  private final @Nullable SchemaPlus defaultSchema;
   private @Nullable JavaTypeFactory typeFactory;
   private @Nullable RelOptPlanner planner;
-  private @Nullable RexExecutor executor;
+  private final @Nullable RexExecutor executor;
 
   // set in STATE_4_VALIDATE
   private @Nullable SqlValidator validator;
diff --git a/core/src/main/java/org/apache/calcite/prepare/Prepare.java b/core/src/main/java/org/apache/calcite/prepare/Prepare.java
index 636e94af15..59006c1337 100644
--- a/core/src/main/java/org/apache/calcite/prepare/Prepare.java
+++ b/core/src/main/java/org/apache/calcite/prepare/Prepare.java
@@ -652,10 +652,9 @@ public abstract class Prepare {
 
     public Materialization(CalciteSchema.TableEntry materializedTable,
         String sql, List<String> viewSchemaPath) {
-      assert materializedTable != null;
-      assert sql != null;
-      this.materializedTable = materializedTable;
-      this.sql = sql;
+      this.materializedTable =
+          requireNonNull(materializedTable, "materializedTable");
+      this.sql = requireNonNull(sql, "sql");
       this.viewSchemaPath = viewSchemaPath;
     }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java b/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
index c14f4d2a49..0786798474 100644
--- a/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
+++ b/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
@@ -54,6 +54,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import static java.util.Objects.requireNonNull;
 
 /**
@@ -76,7 +78,7 @@ public abstract class AbstractRelNode implements RelNode {
    * The digest that uniquely identifies the node.
    */
   @API(since = "1.24", status = API.Status.INTERNAL)
-  protected RelDigest digest;
+  protected final RelDigest digest;
 
   private final RelOptCluster cluster;
 
@@ -84,7 +86,7 @@ public abstract class AbstractRelNode implements RelNode {
   protected final int id;
 
   /** RelTraitSet that describes the traits of this RelNode. */
-  protected RelTraitSet traitSet;
+  protected final RelTraitSet traitSet;
 
   //~ Constructors -----------------------------------------------------------
 
@@ -93,9 +95,8 @@ public abstract class AbstractRelNode implements RelNode {
    */
   protected AbstractRelNode(RelOptCluster cluster, RelTraitSet traitSet) {
     super();
-    assert cluster != null;
-    this.cluster = cluster;
-    this.traitSet = traitSet;
+    this.cluster = requireNonNull(cluster, "cluster");
+    this.traitSet = requireNonNull(traitSet, "traitSet");
     this.id = NEXT_ID.getAndIncrement();
     this.digest = new InnerRelDigest();
   }
@@ -171,8 +172,7 @@ public abstract class AbstractRelNode implements RelNode {
 
   @Override public final RelDataType getRowType() {
     if (rowType == null) {
-      rowType = deriveRowType();
-      assert rowType != null : this;
+      rowType = checkNotNull(deriveRowType(), "null row type for %s", this);
     }
     return rowType;
   }
@@ -239,11 +239,10 @@ public abstract class AbstractRelNode implements RelNode {
       RelMetadataQuery mq) {
     final MetadataFactory factory = cluster.getMetadataFactory();
     final M metadata = factory.query(this, mq, metadataClass);
-    assert metadata != null
-        : "no provider found (rel=" + this + ", m=" + metadataClass
-        + "); a backstop provider is recommended";
+    checkNotNull(metadata, "no provider found (rel=%s, m=%s); "
+        + "a backstop provider is recommended", this, metadataClass);
     // Usually the metadata belongs to the rel that created it. RelSubset and
-    // HepRelVertex are notable exceptions, so disable the assert. It's not
+    // HepRelVertex are notable exceptions, so disable the assertion. It's not
     // worth the performance hit to override this method for them.
     //   assert metadata.rel() == this : "someone else's metadata";
     return metadata;
diff --git a/core/src/main/java/org/apache/calcite/rel/RelDistributions.java b/core/src/main/java/org/apache/calcite/rel/RelDistributions.java
index 769592d39f..7917c9f58f 100644
--- a/core/src/main/java/org/apache/calcite/rel/RelDistributions.java
+++ b/core/src/main/java/org/apache/calcite/rel/RelDistributions.java
@@ -32,6 +32,8 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Objects;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Utilities concerning {@link org.apache.calcite.rel.RelDistribution}.
  */
@@ -96,7 +98,7 @@ public class RelDistributions {
     private final ImmutableIntList keys;
 
     private RelDistributionImpl(Type type, ImmutableIntList keys) {
-      this.type = Objects.requireNonNull(type, "type");
+      this.type = requireNonNull(type, "type");
       this.keys = ImmutableIntList.copyOf(keys);
       assert type != Type.HASH_DISTRIBUTED
           || keys.size() < 2
diff --git a/core/src/main/java/org/apache/calcite/rel/RelFieldCollation.java b/core/src/main/java/org/apache/calcite/rel/RelFieldCollation.java
index 8707b21312..9359f92230 100644
--- a/core/src/main/java/org/apache/calcite/rel/RelFieldCollation.java
+++ b/core/src/main/java/org/apache/calcite/rel/RelFieldCollation.java
@@ -22,6 +22,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.Objects;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Definition of the ordering of one field of a {@link RelNode} whose
  * output is to be sorted.
@@ -241,8 +243,8 @@ public class RelFieldCollation {
       Direction direction,
       NullDirection nullDirection) {
     this.fieldIndex = fieldIndex;
-    this.direction = Objects.requireNonNull(direction, "direction");
-    this.nullDirection = Objects.requireNonNull(nullDirection, "nullDirection");
+    this.direction = requireNonNull(direction, "direction");
+    this.nullDirection = requireNonNull(nullDirection, "nullDirection");
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/convert/ConverterImpl.java b/core/src/main/java/org/apache/calcite/rel/convert/ConverterImpl.java
index cc4264ca26..623e1acc92 100644
--- a/core/src/main/java/org/apache/calcite/rel/convert/ConverterImpl.java
+++ b/core/src/main/java/org/apache/calcite/rel/convert/ConverterImpl.java
@@ -34,7 +34,7 @@ public abstract class ConverterImpl extends SingleRel
     implements Converter {
   //~ Instance fields --------------------------------------------------------
 
-  protected RelTraitSet inTraits;
+  protected final RelTraitSet inTraits;
   protected final @Nullable RelTraitDef traitDef;
 
   //~ Constructors -----------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/convert/ConverterRule.java b/core/src/main/java/org/apache/calcite/rel/convert/ConverterRule.java
index beb7e1b810..10e11d2b71 100644
--- a/core/src/main/java/org/apache/calcite/rel/convert/ConverterRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/convert/ConverterRule.java
@@ -35,6 +35,8 @@ import java.util.function.Predicate;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Abstract base class for a rule which converts from one calling convention to
  * another without changing semantics.
@@ -53,8 +55,8 @@ public abstract class ConverterRule
   /** Creates a <code>ConverterRule</code>. */
   protected ConverterRule(Config config) {
     super(config);
-    this.inTrait = Objects.requireNonNull(config.inTrait());
-    this.outTrait = Objects.requireNonNull(config.outTrait());
+    this.inTrait = requireNonNull(config.inTrait());
+    this.outTrait = requireNonNull(config.outTrait());
 
     // Source and target traits must have same type
     assert inTrait.getTraitDef() == outTrait.getTraitDef();
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Aggregate.java b/core/src/main/java/org/apache/calcite/rel/core/Aggregate.java
index 0736bfa054..57c613b126 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Aggregate.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Aggregate.java
@@ -535,8 +535,8 @@ public abstract class Aggregate extends SingleRel implements Hintable {
         }
         g = bitSet;
       }
-      assert g != null : "groupSet must not be empty";
-      assert g.isEmpty();
+      requireNonNull(g, "groupSet must not be empty");
+      checkArgument(g.isEmpty());
       return true;
     }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/core/AggregateCall.java b/core/src/main/java/org/apache/calcite/rel/core/AggregateCall.java
index aa6ea524ac..687e41c7e7 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/AggregateCall.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/AggregateCall.java
@@ -390,7 +390,7 @@ public class AggregateCall {
       buf.append("APPROXIMATE ");
     }
     if (distinct) {
-      buf.append((argList.size() == 0) ? "DISTINCT" : "DISTINCT ");
+      buf.append(argList.isEmpty() ? "DISTINCT" : "DISTINCT ");
     }
     int i = -1;
     for (RexNode rexNode : rexList) {
diff --git a/core/src/main/java/org/apache/calcite/rel/core/CorrelationId.java b/core/src/main/java/org/apache/calcite/rel/core/CorrelationId.java
index 86d9e3ec0f..8deaa947b6 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/CorrelationId.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/CorrelationId.java
@@ -22,6 +22,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.Set;
 
+import static java.lang.Integer.parseInt;
+
 /**
  * Describes the necessary parameters for an implementation in order to
  * identify and set dynamic variables.
@@ -59,7 +61,7 @@ public class CorrelationId implements Cloneable, Comparable<CorrelationId> {
    * @param name     variable name
    */
   public CorrelationId(String name) {
-    this(Integer.parseInt(name.substring(CORREL_PREFIX.length())), name);
+    this(parseInt(name.substring(CORREL_PREFIX.length())), name);
     assert name.startsWith(CORREL_PREFIX)
         : "Correlation name should start with " + CORREL_PREFIX
         + " actual name is " + name;
diff --git a/core/src/main/java/org/apache/calcite/rel/core/EquiJoin.java b/core/src/main/java/org/apache/calcite/rel/core/EquiJoin.java
index 27fa1ff46d..de5c1add11 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/EquiJoin.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/EquiJoin.java
@@ -24,9 +24,10 @@ import org.apache.calcite.util.ImmutableIntList;
 
 import com.google.common.collect.ImmutableList;
 
-import java.util.Objects;
 import java.util.Set;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Base class for any join whose condition is based on column equality.
  *
@@ -55,8 +56,8 @@ public abstract class EquiJoin extends Join {
       RelNode right, RexNode condition, Set<CorrelationId> variablesSet,
       JoinRelType joinType) {
     super(cluster, traits, ImmutableList.of(), left, right, condition, variablesSet, joinType);
-    this.leftKeys = Objects.requireNonNull(joinInfo.leftKeys);
-    this.rightKeys = Objects.requireNonNull(joinInfo.rightKeys);
+    this.leftKeys = requireNonNull(joinInfo.leftKeys);
+    this.rightKeys = requireNonNull(joinInfo.rightKeys);
     assert joinInfo.isEqui() : "Create EquiJoin with non-equi join condition.";
   }
 
@@ -67,8 +68,8 @@ public abstract class EquiJoin extends Join {
       ImmutableIntList rightKeys, Set<CorrelationId> variablesSet,
       JoinRelType joinType) {
     super(cluster, traits, ImmutableList.of(), left, right, condition, variablesSet, joinType);
-    this.leftKeys = Objects.requireNonNull(leftKeys, "leftKeys");
-    this.rightKeys = Objects.requireNonNull(rightKeys, "rightKeys");
+    this.leftKeys = requireNonNull(leftKeys, "leftKeys");
+    this.rightKeys = requireNonNull(rightKeys, "rightKeys");
   }
 
   @Deprecated // to be removed before 2.0
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Exchange.java b/core/src/main/java/org/apache/calcite/rel/core/Exchange.java
index 0e8c8927b7..b6a59f9e29 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Exchange.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Exchange.java
@@ -33,7 +33,8 @@ import org.apache.calcite.util.Util;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Relational expression that imposes a particular distribution on its input
@@ -59,7 +60,7 @@ public abstract class Exchange extends SingleRel {
   protected Exchange(RelOptCluster cluster, RelTraitSet traitSet, RelNode input,
       RelDistribution distribution) {
     super(cluster, traitSet, input);
-    this.distribution = Objects.requireNonNull(distribution, "distribution");
+    this.distribution = requireNonNull(distribution, "distribution");
 
     assert traitSet.containsIfApplicable(distribution)
         : "traits=" + traitSet + ", distribution=" + distribution;
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Join.java b/core/src/main/java/org/apache/calcite/rel/core/Join.java
index 23d2f923a8..540c5806be 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Join.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Join.java
@@ -50,6 +50,8 @@ import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Relational expression that combines two relational expressions according to
  * some condition.
@@ -99,9 +101,9 @@ public abstract class Join extends BiRel implements Hintable {
       Set<CorrelationId> variablesSet,
       JoinRelType joinType) {
     super(cluster, traitSet, left, right);
-    this.condition = Objects.requireNonNull(condition, "condition");
+    this.condition = requireNonNull(condition, "condition");
     this.variablesSet = ImmutableSet.copyOf(variablesSet);
-    this.joinType = Objects.requireNonNull(joinType, "joinType");
+    this.joinType = requireNonNull(joinType, "joinType");
     this.joinInfo = JoinInfo.of(left, right, condition);
     this.hints = ImmutableList.copyOf(hints);
   }
diff --git a/core/src/main/java/org/apache/calcite/rel/core/JoinInfo.java b/core/src/main/java/org/apache/calcite/rel/core/JoinInfo.java
index e8f20f009a..2a33714838 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/JoinInfo.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/JoinInfo.java
@@ -30,7 +30,8 @@ import com.google.common.collect.ImmutableList;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /** An analyzed join condition.
  *
@@ -50,9 +51,10 @@ public class JoinInfo {
   /** Creates a JoinInfo. */
   protected JoinInfo(ImmutableIntList leftKeys, ImmutableIntList rightKeys,
       ImmutableList<RexNode> nonEquiConditions) {
-    this.leftKeys = Objects.requireNonNull(leftKeys, "leftKeys");
-    this.rightKeys = Objects.requireNonNull(rightKeys, "rightKeys");
-    this.nonEquiConditions = Objects.requireNonNull(nonEquiConditions, "nonEquiConditions");
+    this.leftKeys = requireNonNull(leftKeys, "leftKeys");
+    this.rightKeys = requireNonNull(rightKeys, "rightKeys");
+    this.nonEquiConditions =
+        requireNonNull(nonEquiConditions, "nonEquiConditions");
     assert leftKeys.size() == rightKeys.size();
   }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Match.java b/core/src/main/java/org/apache/calcite/rel/core/Match.java
index dbfd8c9200..a0d106b209 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Match.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Match.java
@@ -45,7 +45,6 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.NavigableSet;
-import java.util.Objects;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeMap;
@@ -53,6 +52,8 @@ import java.util.TreeSet;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Relational expression that represent a MATCH_RECOGNIZE node.
  *
@@ -104,18 +105,18 @@ public abstract class Match extends SingleRel {
       boolean allRows, ImmutableBitSet partitionKeys, RelCollation orderKeys,
       @Nullable RexNode interval) {
     super(cluster, traitSet, input);
-    this.rowType = Objects.requireNonNull(rowType, "rowType");
-    this.pattern = Objects.requireNonNull(pattern, "pattern");
+    this.rowType = requireNonNull(rowType, "rowType");
+    this.pattern = requireNonNull(pattern, "pattern");
     checkArgument(!patternDefinitions.isEmpty());
     this.strictStart = strictStart;
     this.strictEnd = strictEnd;
     this.patternDefinitions = ImmutableMap.copyOf(patternDefinitions);
     this.measures = ImmutableMap.copyOf(measures);
-    this.after = Objects.requireNonNull(after, "after");
+    this.after = requireNonNull(after, "after");
     this.subsets = copyMap(subsets);
     this.allRows = allRows;
-    this.partitionKeys = Objects.requireNonNull(partitionKeys, "partitionKeys");
-    this.orderKeys = Objects.requireNonNull(orderKeys, "orderKeys");
+    this.partitionKeys = requireNonNull(partitionKeys, "partitionKeys");
+    this.orderKeys = requireNonNull(orderKeys, "orderKeys");
     this.interval = interval;
 
     final AggregateFinder aggregateFinder = new AggregateFinder();
@@ -255,7 +256,7 @@ public abstract class Match extends SingleRel {
                 aggregateCalls.size());
         aggregateCalls.add(aggCall);
         Set<String> pv = new PatternVarFinder().go(call.getOperands());
-        if (pv.size() == 0) {
+        if (pv.isEmpty()) {
           pv.add(STAR);
         }
         for (String alpha : pv) {
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Project.java b/core/src/main/java/org/apache/calcite/rel/core/Project.java
index 3c4acb5842..1de67c9228 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Project.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Project.java
@@ -99,10 +99,9 @@ public abstract class Project extends SingleRel implements Hintable {
       RelDataType rowType,
       Set<CorrelationId> variableSet) {
     super(cluster, traits, input);
-    assert rowType != null;
     this.exps = ImmutableList.copyOf(projects);
     this.hints = ImmutableList.copyOf(hints);
-    this.rowType = rowType;
+    this.rowType = requireNonNull(rowType, "rowType");
     this.variablesSet = ImmutableSet.copyOf(variableSet);
     assert isValid(Litmus.THROW, null);
   }
@@ -228,9 +227,8 @@ public abstract class Project extends SingleRel implements Hintable {
   // TODO: replace calls to getNamedProjects
   public final List<RexNode> getAliasedProjects(RelBuilder b) {
     final ImmutableList.Builder<RexNode> builder = ImmutableList.builder();
-    Pair.forEach(exps, getRowType().getFieldList(), (e, f) -> {
-      builder.add(b.alias(e, f.getName()));
-    });
+    Pair.forEach(exps, getRowType().getFieldList(), (e, f) ->
+        builder.add(b.alias(e, f.getName())));
     return builder.build();
   }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/core/RepeatUnion.java b/core/src/main/java/org/apache/calcite/rel/core/RepeatUnion.java
index 073861e924..5c31b4f189 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/RepeatUnion.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/RepeatUnion.java
@@ -31,7 +31,8 @@ import org.apache.calcite.util.Util;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Relational expression that computes a repeat union (recursive union in SQL
@@ -80,7 +81,7 @@ public abstract class RepeatUnion extends BiRel {
     this.all = all;
     this.transientTable = transientTable;
     if (transientTable != null) {
-      Objects.requireNonNull(transientTable.unwrap(TransientTable.class));
+      requireNonNull(transientTable.unwrap(TransientTable.class));
     }
   }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Snapshot.java b/core/src/main/java/org/apache/calcite/rel/core/Snapshot.java
index 7a60b9d2f4..52c4c8ab72 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Snapshot.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Snapshot.java
@@ -35,7 +35,6 @@ import com.google.common.collect.ImmutableList;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
 
 import static java.util.Objects.requireNonNull;
 
@@ -84,7 +83,7 @@ public abstract class Snapshot extends SingleRel implements Hintable {
   protected Snapshot(RelOptCluster cluster, RelTraitSet traitSet, List<RelHint> hints,
       RelNode input, RexNode period) {
     super(cluster, traitSet, input);
-    this.period = Objects.requireNonNull(period, "period");
+    this.period = requireNonNull(period, "period");
     this.hints = ImmutableList.copyOf(hints);
     assert isValid(Litmus.THROW, null);
   }
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Sort.java b/core/src/main/java/org/apache/calcite/rel/core/Sort.java
index 750d27753a..5f83f32c2e 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Sort.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Sort.java
@@ -42,7 +42,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.Collections;
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Relational expression that imposes a particular sort order on its input
@@ -231,7 +232,7 @@ public abstract class Sort extends SingleRel implements Hintable {
 
   @Override public boolean isEnforcer() {
     return offset == null && fetch == null
-        && collation.getFieldCollations().size() > 0;
+        && !collation.getFieldCollations().isEmpty();
   }
 
   /**
@@ -255,7 +256,7 @@ public abstract class Sort extends SingleRel implements Hintable {
     //noinspection StaticPseudoFunctionalStyleMethod
     return Util.transform(collation.getFieldCollations(), field ->
         getCluster().getRexBuilder().makeInputRef(input,
-            Objects.requireNonNull(field, "field").getFieldIndex()));
+            requireNonNull(field, "field").getFieldIndex()));
   }
 
   @Override public RelWriter explainTerms(RelWriter pw) {
diff --git a/core/src/main/java/org/apache/calcite/rel/core/SortExchange.java b/core/src/main/java/org/apache/calcite/rel/core/SortExchange.java
index 9b1653e865..af1cea599a 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/SortExchange.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/SortExchange.java
@@ -26,7 +26,7 @@ import org.apache.calcite.rel.RelInput;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.RelWriter;
 
-import java.util.Objects;
+import static java.util.Objects.requireNonNull;
 
 /**
  * Relational expression that performs {@link Exchange} and {@link Sort}
@@ -57,7 +57,7 @@ public abstract class SortExchange extends Exchange {
   protected SortExchange(RelOptCluster cluster, RelTraitSet traitSet,
       RelNode input, RelDistribution distribution, RelCollation collation) {
     super(cluster, traitSet, input, distribution);
-    this.collation = Objects.requireNonNull(collation, "collation");
+    this.collation = requireNonNull(collation, "collation");
 
     assert traitSet.containsIfApplicable(collation)
         : "traits=" + traitSet + ", collation=" + collation;
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Spool.java b/core/src/main/java/org/apache/calcite/rel/core/Spool.java
index 4bc7e10cf8..5a15520cd6 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Spool.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Spool.java
@@ -24,7 +24,8 @@ import org.apache.calcite.rel.RelWriter;
 import org.apache.calcite.rel.SingleRel;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Relational expression that iterates over its input and, in addition to
@@ -73,8 +74,8 @@ public abstract class Spool extends SingleRel {
   protected Spool(RelOptCluster cluster, RelTraitSet traitSet, RelNode input,
       Type readType, Type writeType) {
     super(cluster, traitSet, input);
-    this.readType = Objects.requireNonNull(readType, "readType");
-    this.writeType = Objects.requireNonNull(writeType, "writeType");
+    this.readType = requireNonNull(readType, "readType");
+    this.writeType = requireNonNull(writeType, "writeType");
   }
 
   @Override public final RelNode copy(RelTraitSet traitSet,
diff --git a/core/src/main/java/org/apache/calcite/rel/core/TableFunctionScan.java b/core/src/main/java/org/apache/calcite/rel/core/TableFunctionScan.java
index baeee2c19e..0a8c6d9cfd 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/TableFunctionScan.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/TableFunctionScan.java
@@ -194,7 +194,7 @@ public abstract class TableFunctionScan extends AbstractRelNode
     // for a no-input UDX, behave like an AbstractRelNode; for a one-input
     // UDX, behave like a SingleRel; for a multi-input UDX, behave like
     // UNION ALL.  TODO jvs 10-Sep-2007: UDX-supplied costing metadata.
-    if (inputs.size() == 0) {
+    if (inputs.isEmpty()) {
       return super.estimateRowCount(mq);
     }
     double nRows = 0.0;
diff --git a/core/src/main/java/org/apache/calcite/rel/core/TableModify.java b/core/src/main/java/org/apache/calcite/rel/core/TableModify.java
index 879052166a..d42020b665 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/TableModify.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/TableModify.java
@@ -73,7 +73,7 @@ public abstract class TableModify extends SingleRel {
   /**
    * The connection to the optimizing session.
    */
-  protected Prepare.CatalogReader catalogReader;
+  protected final Prepare.CatalogReader catalogReader;
 
   /**
    * The table definition.
@@ -149,8 +149,8 @@ public abstract class TableModify extends SingleRel {
     this(input.getCluster(),
         input.getTraitSet(),
         input.getTable("table"),
-        (Prepare.CatalogReader) requireNonNull(
-            input.getTable("table").getRelOptSchema(),
+        requireNonNull(
+            (Prepare.CatalogReader) input.getTable("table").getRelOptSchema(),
             "relOptSchema"),
         input.getInput(),
         requireNonNull(input.getEnum("operation", Operation.class), "operation"),
@@ -217,14 +217,20 @@ public abstract class TableModify extends SingleRel {
     final RelDataType rowType = table.getRowType();
     switch (operation) {
     case UPDATE:
-      assert updateColumnList != null : "updateColumnList must not be null for " + operation;
+      if (updateColumnList == null) {
+        throw new AssertionError("updateColumnList must not be null for "
+            + operation);
+      }
       inputRowType =
           typeFactory.createJoinType(rowType,
               getCatalogReader().createTypeFromProjection(rowType,
                   updateColumnList));
       break;
     case MERGE:
-      assert updateColumnList != null : "updateColumnList must not be null for " + operation;
+      if (updateColumnList == null) {
+        throw new AssertionError("updateColumnList must not be null for "
+            + operation);
+      }
       inputRowType =
           typeFactory.createJoinType(
               typeFactory.createJoinType(rowType, rowType),
diff --git a/core/src/main/java/org/apache/calcite/rel/core/TableScan.java b/core/src/main/java/org/apache/calcite/rel/core/TableScan.java
index 390852f838..0d6c4a9cdd 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/TableScan.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/TableScan.java
@@ -44,9 +44,10 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 import java.util.Set;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Relational operator that returns the contents of a table.
  */
@@ -69,7 +70,7 @@ public abstract class TableScan
   protected TableScan(RelOptCluster cluster, RelTraitSet traitSet,
       List<RelHint> hints, RelOptTable table) {
     super(cluster, traitSet);
-    this.table = Objects.requireNonNull(table, "table");
+    this.table = requireNonNull(table, "table");
     RelOptSchema relOptSchema = table.getRelOptSchema();
     if (relOptSchema != null) {
       cluster.getPlanner().registerSchema(relOptSchema);
diff --git a/core/src/main/java/org/apache/calcite/rel/core/TableSpool.java b/core/src/main/java/org/apache/calcite/rel/core/TableSpool.java
index 0ef0c338d8..bf22d2c962 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/TableSpool.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/TableSpool.java
@@ -23,7 +23,7 @@ import org.apache.calcite.plan.RelTraitSet;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.RelWriter;
 
-import java.util.Objects;
+import static java.util.Objects.requireNonNull;
 
 /**
  * Spool that writes into a table.
@@ -39,7 +39,7 @@ public abstract class TableSpool extends Spool {
   protected TableSpool(RelOptCluster cluster, RelTraitSet traitSet,
       RelNode input, Type readType, Type writeType, RelOptTable table) {
     super(cluster, traitSet, input, readType, writeType);
-    this.table = Objects.requireNonNull(table, "table");
+    this.table = requireNonNull(table, "table");
   }
 
   @Override public RelOptTable getTable() {
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Uncollect.java b/core/src/main/java/org/apache/calcite/rel/core/Uncollect.java
index e19faca671..48e6c8ec2a 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Uncollect.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Uncollect.java
@@ -37,6 +37,8 @@ import java.util.List;
 
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Relational expression that unnests its input's columns into a relation.
  *
@@ -77,7 +79,7 @@ public class Uncollect extends SingleRel {
     super(cluster, traitSet, input);
     this.withOrdinality = withOrdinality;
     this.itemAliases = ImmutableList.copyOf(itemAliases);
-    assert deriveRowType() != null : "invalid child rowtype";
+    requireNonNull(deriveRowType(), "invalid child rowType");
   }
 
   /**
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Values.java b/core/src/main/java/org/apache/calcite/rel/core/Values.java
index ed71753495..e456489338 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Values.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Values.java
@@ -190,7 +190,9 @@ public abstract class Values extends AbstractRelNode implements Hintable {
   }
 
   @Override protected RelDataType deriveRowType() {
-    assert rowType != null : "rowType must not be null for " + this;
+    if (rowType == null) {
+      throw new AssertionError("rowType must not be null for " + this);
+    }
     return rowType;
   }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/externalize/RelDotWriter.java b/core/src/main/java/org/apache/calcite/rel/externalize/RelDotWriter.java
index f5490c0333..f354bda246 100644
--- a/core/src/main/java/org/apache/calcite/rel/externalize/RelDotWriter.java
+++ b/core/src/main/java/org/apache/calcite/rel/externalize/RelDotWriter.java
@@ -50,9 +50,9 @@ public class RelDotWriter extends RelWriterImpl {
    */
   private final Map<RelNode, List<RelNode>> outArcTable = new LinkedHashMap<>();
 
-  private Map<RelNode, String> nodeLabels = new HashMap<>();
+  private final Map<RelNode, String> nodeLabels = new HashMap<>();
 
-  private Multimap<RelNode, String> nodeStyles = HashMultimap.create();
+  private final Multimap<RelNode, String> nodeStyles = HashMultimap.create();
 
   private final WriteOption option;
 
diff --git a/core/src/main/java/org/apache/calcite/rel/externalize/RelJson.java b/core/src/main/java/org/apache/calcite/rel/externalize/RelJson.java
index c1bcab8616..010f47d0f7 100644
--- a/core/src/main/java/org/apache/calcite/rel/externalize/RelJson.java
+++ b/core/src/main/java/org/apache/calcite/rel/externalize/RelJson.java
@@ -662,10 +662,10 @@ public class RelJson {
 
   private Object toJson(RexWindow window) {
     final Map<String, @Nullable Object> map = jsonBuilder().map();
-    if (window.partitionKeys.size() > 0) {
+    if (!window.partitionKeys.isEmpty()) {
       map.put("partition", toJson(window.partitionKeys));
     }
-    if (window.orderKeys.size() > 0) {
+    if (!window.orderKeys.isEmpty()) {
       map.put("order", toJson(window.orderKeys));
     }
     if (window.getLowerBound() == null) {
@@ -977,7 +977,8 @@ public class RelJson {
     }
   }
 
-  private @Nullable RexWindowExclusion toRexWindowExclusion(@Nullable Map<String, Object> map) {
+  private static @Nullable RexWindowExclusion toRexWindowExclusion(
+      @Nullable Map<String, Object> map) {
     if (map == null) {
       return null;
     }
diff --git a/core/src/main/java/org/apache/calcite/rel/externalize/RelWriterImpl.java b/core/src/main/java/org/apache/calcite/rel/externalize/RelWriterImpl.java
index 1d242f21e9..9df7a3c27e 100644
--- a/core/src/main/java/org/apache/calcite/rel/externalize/RelWriterImpl.java
+++ b/core/src/main/java/org/apache/calcite/rel/externalize/RelWriterImpl.java
@@ -155,7 +155,7 @@ public class RelWriterImpl implements RelWriter {
 
   private boolean checkInputsPresentInExplain(RelNode node) {
     int i = 0;
-    if (values.size() > 0 && values.get(0).left.equals("subset")) {
+    if (!values.isEmpty() && values.get(0).left.equals("subset")) {
       ++i;
     }
     for (RelNode input : node.getInputs()) {
diff --git a/core/src/main/java/org/apache/calcite/rel/externalize/RelXmlWriter.java b/core/src/main/java/org/apache/calcite/rel/externalize/RelXmlWriter.java
index 7078f9add1..b11098240e 100644
--- a/core/src/main/java/org/apache/calcite/rel/externalize/RelXmlWriter.java
+++ b/core/src/main/java/org/apache/calcite/rel/externalize/RelXmlWriter.java
@@ -35,7 +35,7 @@ public class RelXmlWriter extends RelWriterImpl {
   //~ Instance fields --------------------------------------------------------
 
   private final XmlOutput xmlOutput;
-  boolean generic = true;
+  final boolean generic = true;
 
   //~ Constructors -----------------------------------------------------------
 
diff --git a/core/src/main/java/org/apache/calcite/rel/hint/CompositeHintPredicate.java b/core/src/main/java/org/apache/calcite/rel/hint/CompositeHintPredicate.java
index da9dba1085..fc7bd9de35 100644
--- a/core/src/main/java/org/apache/calcite/rel/hint/CompositeHintPredicate.java
+++ b/core/src/main/java/org/apache/calcite/rel/hint/CompositeHintPredicate.java
@@ -20,6 +20,8 @@ import org.apache.calcite.rel.RelNode;
 
 import com.google.common.collect.ImmutableList;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 /**
  * A {@link HintPredicate} to combine multiple hint predicates into one.
  *
@@ -35,8 +37,8 @@ public class CompositeHintPredicate implements HintPredicate {
 
   //~ Instance fields --------------------------------------------------------
 
-  private ImmutableList<HintPredicate> predicates;
-  private Composition composition;
+  private final ImmutableList<HintPredicate> predicates;
+  private final Composition composition;
 
   /**
    * Creates a {@link CompositeHintPredicate} with a {@link Composition}
@@ -47,12 +49,8 @@ public class CompositeHintPredicate implements HintPredicate {
    * to create a {@link CompositeHintPredicate}.
    */
   CompositeHintPredicate(Composition composition, HintPredicate... predicates) {
-    assert predicates != null;
-    assert predicates.length > 1;
-    for (HintPredicate predicate : predicates) {
-      assert predicate != null;
-    }
     this.predicates = ImmutableList.copyOf(predicates);
+    checkArgument(this.predicates.size() > 1);
     this.composition = composition;
   }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/hint/HintStrategy.java b/core/src/main/java/org/apache/calcite/rel/hint/HintStrategy.java
index 8dcdb5e093..4f28fd5a94 100644
--- a/core/src/main/java/org/apache/calcite/rel/hint/HintStrategy.java
+++ b/core/src/main/java/org/apache/calcite/rel/hint/HintStrategy.java
@@ -23,7 +23,7 @@ import com.google.common.collect.ImmutableSet;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
 
-import java.util.Objects;
+import static java.util.Objects.requireNonNull;
 
 /**
  * Represents a hint strategy entry of {@link HintStrategyTable}.
@@ -85,14 +85,14 @@ public class HintStrategy {
     private ImmutableSet<ConverterRule> converterRules;
 
     private Builder(HintPredicate predicate) {
-      this.predicate = Objects.requireNonNull(predicate, "predicate");
+      this.predicate = requireNonNull(predicate, "predicate");
       this.excludedRules = ImmutableSet.of();
       this.converterRules = ImmutableSet.of();
     }
 
     /** Registers a hint option checker to validate the hint options. */
     public Builder optionChecker(HintOptionChecker optionChecker) {
-      this.optionChecker = Objects.requireNonNull(optionChecker, "optionChecker");
+      this.optionChecker = requireNonNull(optionChecker, "optionChecker");
       return this;
     }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/hint/HintStrategyTable.java b/core/src/main/java/org/apache/calcite/rel/hint/HintStrategyTable.java
index a2e0a3233e..a8de62f186 100644
--- a/core/src/main/java/org/apache/calcite/rel/hint/HintStrategyTable.java
+++ b/core/src/main/java/org/apache/calcite/rel/hint/HintStrategyTable.java
@@ -119,7 +119,7 @@ public class HintStrategyTable {
    * the given {@code rule} should be excluded. */
   public boolean isRuleExcluded(Hintable hintable, RelOptRule rule) {
     final List<RelHint> hints = hintable.getHints();
-    if (hints.size() == 0) {
+    if (hints.isEmpty()) {
       return false;
     }
 
@@ -141,7 +141,7 @@ public class HintStrategyTable {
       Set<ConverterRule> converterRules,
       Hintable hintable) {
     // If no converter rules are specified, we assume the conversion is possible.
-    return converterRules.size() == 0
+    return converterRules.isEmpty()
         || converterRules.stream()
             .anyMatch(converterRule -> converterRule.convert((RelNode) hintable) != null);
   }
diff --git a/core/src/main/java/org/apache/calcite/rel/hint/Hintable.java b/core/src/main/java/org/apache/calcite/rel/hint/Hintable.java
index 520f9f721b..5ca742dba8 100644
--- a/core/src/main/java/org/apache/calcite/rel/hint/Hintable.java
+++ b/core/src/main/java/org/apache/calcite/rel/hint/Hintable.java
@@ -24,9 +24,10 @@ import com.google.common.collect.ImmutableList;
 import java.util.ArrayList;
 import java.util.LinkedHashSet;
 import java.util.List;
-import java.util.Objects;
 import java.util.Set;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * {@link Hintable} is a kind of {@link RelNode} that can attach {@link RelHint}s.
  *
@@ -60,9 +61,8 @@ public interface Hintable {
    * @return Relational expression with the hints {@code hintList} attached
    */
   default RelNode attachHints(List<RelHint> hintList) {
-    Objects.requireNonNull(hintList, "hintList");
     final Set<RelHint> hints = new LinkedHashSet<>(getHints());
-    hints.addAll(hintList);
+    hints.addAll(requireNonNull(hintList, "hintList"));
     return withHints(new ArrayList<>(hints));
   }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/hint/NodeTypeHintPredicate.java b/core/src/main/java/org/apache/calcite/rel/hint/NodeTypeHintPredicate.java
index 6dbfa6b75a..f2a02affa1 100644
--- a/core/src/main/java/org/apache/calcite/rel/hint/NodeTypeHintPredicate.java
+++ b/core/src/main/java/org/apache/calcite/rel/hint/NodeTypeHintPredicate.java
@@ -31,6 +31,8 @@ import org.apache.calcite.rel.core.TableScan;
 import org.apache.calcite.rel.core.Values;
 import org.apache.calcite.rel.core.Window;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A hint predicate that specifies which kind of relational
  * expression the hint can be applied to.
@@ -115,17 +117,17 @@ public class NodeTypeHintPredicate implements HintPredicate {
 
     /** Relational expression clazz that the hint can apply to. */
     @SuppressWarnings("ImmutableEnumChecker")
-    private Class<?> relClazz;
+    private final Class<?> relClazz;
 
     NodeType(Class<?> relClazz) {
       this.relClazz = relClazz;
     }
   }
 
-  private NodeType nodeType;
+  private final NodeType nodeType;
 
   public NodeTypeHintPredicate(NodeType nodeType) {
-    this.nodeType = nodeType;
+    this.nodeType = requireNonNull(nodeType, "nodeType");
   }
 
   @Override public boolean apply(RelHint hint, RelNode rel) {
diff --git a/core/src/main/java/org/apache/calcite/rel/hint/RelHint.java b/core/src/main/java/org/apache/calcite/rel/hint/RelHint.java
index 0312d2d138..826962fdbf 100644
--- a/core/src/main/java/org/apache/calcite/rel/hint/RelHint.java
+++ b/core/src/main/java/org/apache/calcite/rel/hint/RelHint.java
@@ -30,6 +30,8 @@ import java.util.Objects;
 
 import static com.google.common.base.Preconditions.checkState;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Hint attached to a relation expression.
  *
@@ -104,10 +106,8 @@ public class RelHint {
       String hintName,
       @Nullable List<String> listOption,
       @Nullable Map<String, String> kvOptions) {
-    Objects.requireNonNull(inheritPath, "inheritPath");
-    Objects.requireNonNull(hintName, "hintName");
     this.inheritPath = ImmutableList.copyOf(inheritPath);
-    this.hintName = hintName;
+    this.hintName = requireNonNull(hintName, "hintName");
     this.listOptions = listOption == null ? ImmutableList.of() : ImmutableList.copyOf(listOption);
     this.kvOptions = kvOptions == null ? ImmutableMap.of() : ImmutableMap.copyOf(kvOptions);
   }
@@ -126,7 +126,7 @@ public class RelHint {
    * @return the new {@code RelHint}
    */
   public RelHint copy(List<Integer> inheritPath) {
-    Objects.requireNonNull(inheritPath, "inheritPath");
+    requireNonNull(inheritPath, "inheritPath");
     return new RelHint(inheritPath, hintName, listOptions, kvOptions);
   }
 
@@ -155,12 +155,12 @@ public class RelHint {
         .append(this.hintName)
         .append(" inheritPath:")
         .append(this.inheritPath);
-    if (this.listOptions.size() > 0 || this.kvOptions.size() > 0) {
+    if (!this.listOptions.isEmpty() || !this.kvOptions.isEmpty()) {
       builder.append(" options:");
-      if (this.listOptions.size() > 0) {
-        builder.append(this.listOptions.toString());
+      if (!this.listOptions.isEmpty()) {
+        builder.append(this.listOptions);
       } else {
-        builder.append(this.kvOptions.toString());
+        builder.append(this.kvOptions);
       }
     }
     builder.append("]");
@@ -171,7 +171,7 @@ public class RelHint {
 
   /** Builder for {@link RelHint}. */
   public static class Builder {
-    private String hintName;
+    private final String hintName;
     private List<Integer> inheritPath;
 
     private List<String> listOptions;
@@ -186,7 +186,7 @@ public class RelHint {
 
     /** Sets up the inherit path with given integer list. */
     public Builder inheritPath(Iterable<Integer> inheritPath) {
-      this.inheritPath = ImmutableList.copyOf(Objects.requireNonNull(inheritPath, "inheritPath"));
+      this.inheritPath = ImmutableList.copyOf(inheritPath);
       return this;
     }
 
@@ -198,7 +198,7 @@ public class RelHint {
 
     /** Add a hint option as string. */
     public Builder hintOption(String hintOption) {
-      Objects.requireNonNull(hintOption, "hintOption");
+      requireNonNull(hintOption, "hintOption");
       checkState(this.kvOptions.isEmpty(),
           "List options and key value options can not be mixed in");
       this.listOptions.add(hintOption);
@@ -207,7 +207,7 @@ public class RelHint {
 
     /** Add multiple string hint options. */
     public Builder hintOptions(Iterable<String> hintOptions) {
-      Objects.requireNonNull(hintOptions, "hintOptions");
+      requireNonNull(hintOptions, "hintOptions");
       checkState(this.kvOptions.isEmpty(),
           "List options and key value options can not be mixed in");
       this.listOptions = ImmutableList.copyOf(hintOptions);
@@ -216,8 +216,8 @@ public class RelHint {
 
     /** Add a hint option as string key-value pair. */
     public Builder hintOption(String optionKey, String optionValue) {
-      Objects.requireNonNull(optionKey, "optionKey");
-      Objects.requireNonNull(optionValue, "optionValue");
+      requireNonNull(optionKey, "optionKey");
+      requireNonNull(optionValue, "optionValue");
       checkState(this.listOptions.isEmpty(),
           "List options and key value options can not be mixed in");
       this.kvOptions.put(optionKey, optionValue);
@@ -226,7 +226,7 @@ public class RelHint {
 
     /** Add multiple string key-value pair hint options. */
     public Builder hintOptions(Map<String, String> kvOptions) {
-      Objects.requireNonNull(kvOptions, "kvOptions");
+      requireNonNull(kvOptions, "kvOptions");
       checkState(this.listOptions.isEmpty(),
           "List options and key value options can not be mixed in");
       this.kvOptions = kvOptions;
diff --git a/core/src/main/java/org/apache/calcite/rel/logical/LogicalAsofJoin.java b/core/src/main/java/org/apache/calcite/rel/logical/LogicalAsofJoin.java
index 4f68408694..1834adcaac 100644
--- a/core/src/main/java/org/apache/calcite/rel/logical/LogicalAsofJoin.java
+++ b/core/src/main/java/org/apache/calcite/rel/logical/LogicalAsofJoin.java
@@ -124,8 +124,7 @@ public final class LogicalAsofJoin extends AsofJoin {
     if (this == obj) {
       return true;
     }
-    LogicalAsofJoin asofObj = (LogicalAsofJoin) obj;
-    assert asofObj != null;
+    LogicalAsofJoin asofObj = requireNonNull((LogicalAsofJoin) obj);
     return deepEquals0(obj)
         && matchCondition.equals(asofObj.matchCondition)
         && systemFieldList.equals(asofObj.systemFieldList);
diff --git a/core/src/main/java/org/apache/calcite/rel/logical/LogicalFilter.java b/core/src/main/java/org/apache/calcite/rel/logical/LogicalFilter.java
index 829117c784..ca67a1d0e1 100644
--- a/core/src/main/java/org/apache/calcite/rel/logical/LogicalFilter.java
+++ b/core/src/main/java/org/apache/calcite/rel/logical/LogicalFilter.java
@@ -42,6 +42,8 @@ import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Sub-class of {@link org.apache.calcite.rel.core.Filter}
  * not targeted at any particular engine or calling convention.
@@ -71,7 +73,7 @@ public final class LogicalFilter extends Filter {
       RexNode condition,
       ImmutableSet<CorrelationId> variablesSet) {
     super(cluster, traitSet, hints, child, condition);
-    this.variablesSet = Objects.requireNonNull(variablesSet, "variablesSet");
+    this.variablesSet = requireNonNull(variablesSet, "variablesSet");
   }
 
   /**
diff --git a/core/src/main/java/org/apache/calcite/rel/logical/LogicalJoin.java b/core/src/main/java/org/apache/calcite/rel/logical/LogicalJoin.java
index a0e8b0ffa5..9504f01e55 100644
--- a/core/src/main/java/org/apache/calcite/rel/logical/LogicalJoin.java
+++ b/core/src/main/java/org/apache/calcite/rel/logical/LogicalJoin.java
@@ -35,7 +35,6 @@ import com.google.common.collect.ImmutableSet;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
@@ -145,7 +144,7 @@ public final class LogicalJoin extends Join {
    */
   public LogicalJoin(RelInput input) {
     this(input.getCluster(), input.getCluster().traitSetOf(Convention.NONE),
-        new ArrayList<>(),
+        ImmutableList.of(),
         input.getInputs().get(0), input.getInputs().get(1),
         requireNonNull(input.getExpression("condition"), "condition"),
         ImmutableSet.of(),
diff --git a/core/src/main/java/org/apache/calcite/rel/logical/LogicalWindow.java b/core/src/main/java/org/apache/calcite/rel/logical/LogicalWindow.java
index 3ea854331c..1dcff97b18 100644
--- a/core/src/main/java/org/apache/calcite/rel/logical/LogicalWindow.java
+++ b/core/src/main/java/org/apache/calcite/rel/logical/LogicalWindow.java
@@ -57,6 +57,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Sub-class of {@link org.apache.calcite.rel.core.Window}
  * not targeted at any particular engine or calling convention.
@@ -245,8 +247,7 @@ public final class LogicalWindow extends Window {
           @Override public RexNode visitOver(RexOver over) {
             // Look up the aggCall which this expr was translated to.
             final Window.RexWinAggCall aggCall =
-                aggMap.get(origToNewOver.get(over));
-            assert aggCall != null;
+                requireNonNull(aggMap.get(origToNewOver.get(over)));
             assert RelOptUtil.eq(
                 "over",
                 over.getType(),
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java b/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
index 5fb0127858..135b11e110 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
@@ -36,13 +36,11 @@ import org.codehaus.commons.compiler.CompilerFactoryFactory;
 import org.codehaus.commons.compiler.ICompilerFactory;
 import org.codehaus.commons.compiler.ISimpleCompiler;
 
-import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.List;
-import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
 
@@ -137,7 +135,7 @@ public class JaninoRelMetadataProvider implements RelMetadataProvider, MetadataH
     try {
       return compile(handlerNameAndGeneratedCode.getHandlerName(),
           handlerNameAndGeneratedCode.getGeneratedCode(), handlerClass, uniqueHandlers);
-    } catch (CompileException | IOException e) {
+    } catch (CompileException e) {
       throw new RuntimeException("Error compiling:\n"
           + handlerNameAndGeneratedCode.getGeneratedCode(), e);
     }
@@ -146,10 +144,11 @@ public class JaninoRelMetadataProvider implements RelMetadataProvider, MetadataH
 
   static  <MH extends MetadataHandler<?>> MH compile(String className,
       String generatedCode, Class<MH> handlerClass,
-      List<? extends Object> argList) throws CompileException, IOException {
+      List<? extends Object> argList) throws CompileException {
     final ICompilerFactory compilerFactory;
     ClassLoader classLoader =
-        Objects.requireNonNull(JaninoRelMetadataProvider.class.getClassLoader(), "classLoader");
+        requireNonNull(JaninoRelMetadataProvider.class.getClassLoader(),
+            "classLoader");
     try {
       compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(classLoader);
     } catch (Exception e) {
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java b/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java
index 10ed040570..31caa39ed2 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java
@@ -370,7 +370,7 @@ public class ReflectiveRelMetadataProvider
   /** Extended work space. */
   @Deprecated // to be removed before 2.0
   static class Space2 extends Space {
-    private Class<Metadata> metadataClass0;
+    private final Class<Metadata> metadataClass0;
 
     Space2(Class<Metadata> metadataClass0,
         ImmutableMultimap<Method, MetadataHandler<?>> providerMap) {
@@ -382,7 +382,7 @@ public class ReflectiveRelMetadataProvider
     public static Space2 create(
         MetadataHandler<?> target,
         ImmutableList<Method> methods) {
-      assert methods.size() > 0;
+      assert !methods.isEmpty();
       final Method method0 = methods.get(0);
       //noinspection unchecked
       Class<Metadata> metadataClass0 = (Class) method0.getDeclaringClass();
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java
index ffe02f9e82..6ffe9c1f62 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java
@@ -70,11 +70,12 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.NavigableSet;
-import java.util.Objects;
 import java.util.SortedSet;
 import java.util.TreeSet;
 import java.util.stream.Collectors;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * RelMdCollation supplies a default implementation of
  * {@link org.apache.calcite.rel.metadata.RelMetadataQuery#collations}
@@ -246,7 +247,7 @@ public class RelMdCollation
   public @Nullable ImmutableList<RelCollation> collations(RelSubset rel,
       RelMetadataQuery mq) {
     return copyOf(
-        Objects.requireNonNull(
+        requireNonNull(
             rel.getTraitSet().getTraits(RelCollationTraitDef.INSTANCE)));
   }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnOrigins.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnOrigins.java
index 0feeb8f7ae..cbf48990ff 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnOrigins.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnOrigins.java
@@ -151,10 +151,8 @@ public class RelMdColumnOrigins
         return rel.getProgram().expandLocalRef(localRef);
       }
     };
-    final List<RexNode> projects = new ArrayList<>();
-    for (RexNode rex : rexShuttle.apply(rel.getProgram().getProjectList())) {
-      projects.add(rex);
-    }
+    final List<RexNode> projects =
+        new ArrayList<>(rexShuttle.apply(rel.getProgram().getProjectList()));
     final RexNode rexNode = projects.get(iOutputColumn);
     if (rexNode instanceof RexInputRef) {
       // Direct reference:  no derivation added.
@@ -211,7 +209,7 @@ public class RelMdColumnOrigins
     final Set<RelColumnOrigin> set = new HashSet<>();
     Set<RelColumnMapping> mappings = rel.getColumnMappings();
     if (mappings == null) {
-      if (rel.getInputs().size() > 0) {
+      if (!rel.getInputs().isEmpty()) {
         // This is a non-leaf transformation:  say we don't
         // know about origins, because there are probably
         // columns below.
@@ -248,7 +246,7 @@ public class RelMdColumnOrigins
     // it's up to the plugin writer to override with the
     // correct information.
 
-    if (rel.getInputs().size() > 0) {
+    if (!rel.getInputs().isEmpty()) {
       // No generic logic available for non-leaf rels.
       return null;
     }
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java
index 92aa73c243..6bbae1b78d 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java
@@ -43,6 +43,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 /**
  * RelMdCollation supplies a default implementation of
  * {@link RelMetadataQuery#distribution}
@@ -147,7 +149,8 @@ public class RelMdDistribution
    * {@link org.apache.calcite.rel.core.Calc}'s distribution. */
   public static RelDistribution calc(RelMetadataQuery mq, RelNode input,
       RexProgram program) {
-    assert program.getCondition() != null || !program.getProjectList().isEmpty();
+    checkArgument(program.getCondition() != null
+        || !program.getProjectList().isEmpty());
     final RelDistribution inputDistribution = mq.distribution(input);
     if (!program.getProjectList().isEmpty()) {
       final Mappings.TargetMapping mapping =
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPercentageOriginalRows.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPercentageOriginalRows.java
index e64514def1..4e530f8809 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPercentageOriginalRows.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPercentageOriginalRows.java
@@ -130,7 +130,7 @@ public class RelMdPercentageOriginalRows {
       return null;
     }
 
-    if (rel.getInputs().size() == 0) {
+    if (rel.getInputs().isEmpty()) {
       // Assume no filtering happening at leaf.
       return 1.0;
     }
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
index 7cc9aadbd3..ef0687f6e3 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
@@ -567,7 +567,7 @@ public class RelMdPredicates
    */
   public RelOptPredicateList getPredicates(Values values, RelMetadataQuery mq) {
     ImmutableList<ImmutableList<RexLiteral>> tuples = values.tuples;
-    if (tuples.size() > 0) {
+    if (!tuples.isEmpty()) {
       Set<Integer> constants = new HashSet<>();
       IntStream.range(0, tuples.size()).boxed().forEach(constants::add);
       List<RexLiteral> firstTuple = new ArrayList<>(tuples.get(0));
@@ -826,7 +826,7 @@ public class RelMdPredicates
             RelOptUtil.conjunctions(rightChildPredicates),
             inferredPredicates, EMPTY_LIST);
       default:
-        assert inferredPredicates.size() == 0;
+        assert inferredPredicates.isEmpty();
         return RelOptPredicateList.EMPTY;
       }
     }
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java
index 709b8d11c7..5faaeaa85d 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java
@@ -73,7 +73,7 @@ public class RelMdSelectivity
 
   public @Nullable Double getSelectivity(Union rel, RelMetadataQuery mq,
       @Nullable RexNode predicate) {
-    if ((rel.getInputs().size() == 0) || (predicate == null)) {
+    if (rel.getInputs().isEmpty() || predicate == null) {
       return 1.0;
     }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUniqueKeys.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUniqueKeys.java
index 9e7d84a838..31707997ea 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUniqueKeys.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUniqueKeys.java
@@ -300,8 +300,8 @@ public class RelMdUniqueKeys
    * Return the keys that are constant by virtue of equality with a constant
    * (literal or scalar query result) on the other side of a join.
    */
-  private ImmutableBitSet getConstantJoinKeys(ImmutableIntList keys, ImmutableIntList otherKeys,
-      RelNode otherRel, RelMetadataQuery mq) {
+  private static ImmutableBitSet getConstantJoinKeys(ImmutableIntList keys,
+      ImmutableIntList otherKeys, RelNode otherRel, RelMetadataQuery mq) {
     Double maxRowCount = mq.getMaxRowCount(otherRel);
     ImmutableBitSet otherConstants;
     if (maxRowCount != null && maxRowCount <= 1.0d) {
@@ -363,15 +363,17 @@ public class RelMdUniqueKeys
   }
 
   /**
-   * Returns the subset of the supplied keys that are not a superset of any of the other keys.
-   * Given {@code {0},{1},{1,2}}, returns {@code {0},{1}}
+   * Returns the subset of the supplied keys that are not a superset of the
+   * other keys.  Given {@code {0},{1},{1,2}}, returns {@code {0},{1}}.
    */
-  private Set<ImmutableBitSet> filterSupersets(Set<ImmutableBitSet> uniqueKeys) {
+  private static Set<ImmutableBitSet> filterSupersets(
+      Set<ImmutableBitSet> uniqueKeys) {
     Set<ImmutableBitSet> minimalKeys = new HashSet<>();
     outer:
     for (ImmutableBitSet candidateKey : uniqueKeys) {
       for (ImmutableBitSet possibleSubset : uniqueKeys) {
-        if (!candidateKey.equals(possibleSubset) && candidateKey.contains(possibleSubset)) {
+        if (!candidateKey.equals(possibleSubset)
+            && candidateKey.contains(possibleSubset)) {
           continue outer;
         }
       }
@@ -386,7 +388,8 @@ public class RelMdUniqueKeys
    * it is part of a simple group by and/or it is "passed through" unmodified by a
    * {@link RelMdColumnUniqueness#PASSTHROUGH_AGGREGATIONS pass-through aggregation function}.
    */
-  private Set<ImmutableBitSet> getPassedThroughCols(ImmutableBitSet inputColumns, Aggregate rel) {
+  private static Set<ImmutableBitSet> getPassedThroughCols(
+      ImmutableBitSet inputColumns, Aggregate rel) {
     checkArgument(Aggregate.isSimple(rel));
     Set<ImmutableBitSet> conbinations = new HashSet<>();
     conbinations.add(ImmutableBitSet.of());
@@ -409,7 +412,8 @@ public class RelMdUniqueKeys
    * group by and/or it is "passed through" unmodified by a
    * {@link RelMdColumnUniqueness#PASSTHROUGH_AGGREGATIONS pass-through aggregation function}.
    */
-  private ImmutableBitSet getPassedThroughCols(Integer inputColumn, Aggregate rel) {
+  private static ImmutableBitSet getPassedThroughCols(Integer inputColumn,
+      Aggregate rel) {
     final ImmutableBitSet.Builder builder = ImmutableBitSet.builder();
     if (rel.getGroupSet().get(inputColumn)) {
       builder.set(inputColumn);
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java
index 1b1fad4571..48d72bbfe7 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java
@@ -62,6 +62,8 @@ import static com.google.common.base.Preconditions.checkArgument;
 
 import static org.apache.calcite.util.NumberUtil.multiply;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * RelMdUtil provides utility methods used by the metadata provider methods.
  */
@@ -108,9 +110,7 @@ public class RelMdUtil {
     RexCall call = (RexCall) artificialSelectivityFuncNode;
     assert call.getOperator() == ARTIFICIAL_SELECTIVITY_FUNC;
     RexNode operand = call.getOperands().get(0);
-    @SuppressWarnings("unboxing.of.nullable")
-    double doubleValue = ((RexLiteral) operand).getValueAs(Double.class);
-    return doubleValue;
+    return RexLiteral.numberValue(operand).doubleValue();
   }
 
   /**
@@ -905,12 +905,12 @@ public class RelMdUtil {
    * cardinality of its result. */
   private static class CardOfProjExpr extends RexVisitorImpl<@Nullable Double> {
     private final RelMetadataQuery mq;
-    private Project rel;
+    private final Project rel;
 
     CardOfProjExpr(RelMetadataQuery mq, Project rel) {
       super(true);
-      this.mq = mq;
-      this.rel = rel;
+      this.mq = requireNonNull(mq, "mq");
+      this.rel = requireNonNull(rel, "rel");
     }
 
     @Override public @Nullable Double visitInputRef(RexInputRef var) {
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java
index 047f05749d..b2ea8c23da 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java
@@ -446,7 +446,7 @@ public class RelMetadataQuery extends RelMetadataQueryBase {
       return null;
     }
     final Set<RelColumnOrigin> colOrigins = getColumnOrigins(rel, 0);
-    if (colOrigins == null || colOrigins.size() == 0) {
+    if (colOrigins == null || colOrigins.isEmpty()) {
       return null;
     }
     return colOrigins.iterator().next().getOriginTable();
diff --git a/core/src/main/java/org/apache/calcite/rel/mutable/MutableRel.java b/core/src/main/java/org/apache/calcite/rel/mutable/MutableRel.java
index 1bbb849b82..71f6790d64 100644
--- a/core/src/main/java/org/apache/calcite/rel/mutable/MutableRel.java
+++ b/core/src/main/java/org/apache/calcite/rel/mutable/MutableRel.java
@@ -27,7 +27,8 @@ import com.google.common.collect.Lists;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /** Mutable equivalent of {@link RelNode}.
  *
@@ -71,9 +72,9 @@ public abstract class MutableRel {
 
   protected MutableRel(RelOptCluster cluster,
       RelDataType rowType, MutableRelType type) {
-    this.cluster = Objects.requireNonNull(cluster, "cluster");
-    this.rowType = Objects.requireNonNull(rowType, "rowType");
-    this.type = Objects.requireNonNull(type, "type");
+    this.cluster = requireNonNull(cluster, "cluster");
+    this.rowType = requireNonNull(rowType, "rowType");
+    this.type = requireNonNull(type, "type");
   }
 
   public @Nullable MutableRel getParent() {
diff --git a/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java b/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
index b1f75dd18f..118451e379 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
@@ -1344,17 +1344,14 @@ public class RelToSqlConverter extends SqlImplementor
   /** Stack frame. */
   private static class Frame {
     private final RelNode parent;
-    @SuppressWarnings("unused")
-    private final int ordinalInParent;
     private final RelNode r;
     private final boolean anon;
     private final boolean ignoreClauses;
     private final ImmutableSet<? extends Clause> expectedClauses;
 
-    Frame(RelNode parent, int ordinalInParent, RelNode r, boolean anon,
+    Frame(RelNode parent, int unusedOrdinalInParent, RelNode r, boolean anon,
         boolean ignoreClauses, Iterable<? extends Clause> expectedClauses) {
       this.parent = requireNonNull(parent, "parent");
-      this.ordinalInParent = ordinalInParent;
       this.r = requireNonNull(r, "r");
       this.anon = anon;
       this.ignoreClauses = ignoreClauses;
diff --git a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
index b50e4e259d..ca6e357469 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
@@ -304,8 +304,10 @@ public abstract class SqlImplementor {
         node = operator.createCall(POS, node, result.asSelect());
       }
     }
-    assert node != null : "set op must have at least one input, operator = " + operator
-        + ", rel = " + rel;
+    if (node == null) {
+      throw new AssertionError("set op must have at least one input, operator "
+          + operator + ", rel " + rel);
+    }
     final List<Clause> clauses =
         Expressions.list(Clause.SET_OP);
     return result(node, clauses, rel, null);
@@ -670,8 +672,7 @@ public abstract class SqlImplementor {
         case CORREL_VARIABLE:
           final RexCorrelVariable variable = (RexCorrelVariable) referencedExpr;
           final Context correlAliasContext = getAliasContext(variable);
-          final RexFieldAccess lastAccess = accesses.pollLast();
-          assert lastAccess != null;
+          final RexFieldAccess lastAccess = requireNonNull(accesses.pollLast());
           sqlIdentifier = (SqlIdentifier) correlAliasContext
               .field(lastAccess.getField().getIndex());
           break;
@@ -1059,10 +1060,8 @@ public abstract class SqlImplementor {
           new SqlNodeList(toSql(program, rexWindow.partitionKeys), POS);
 
       List<SqlNode> orderNodes = Expressions.list();
-      if (rexWindow.orderKeys != null) {
-        for (RexFieldCollation rfc : rexWindow.orderKeys) {
-          addOrderItem(orderNodes, program, rfc);
-        }
+      for (RexFieldCollation rfc : rexWindow.orderKeys) {
+        addOrderItem(orderNodes, program, rfc);
       }
       final SqlNodeList orderList =
           new SqlNodeList(orderNodes, POS);
@@ -1234,7 +1233,7 @@ public abstract class SqlImplementor {
     /** Converts a call to an aggregate function to an expression. */
     public SqlNode toSql(AggregateCall aggCall) {
       return toSql(aggCall.getAggregation(), aggCall.isDistinct(),
-          Util.transform(aggCall.rexList, e -> toSql((RexProgram) null, e)),
+          Util.transform(aggCall.rexList, e -> toSql(null, e)),
           Util.transform(aggCall.getArgList(), this::field),
           aggCall.filterArg, aggCall.collation, aggCall.isApproximate());
     }
@@ -1458,7 +1457,7 @@ public abstract class SqlImplementor {
       //noinspection unchecked
       final List<RexLiteral> list = castNonNull(literal.getValueAs(List.class));
       return SqlStdOperatorTable.ROW.createCall(POS,
-          list.stream().map(e -> toSql(e))
+          list.stream().map(SqlImplementor::toSql)
               .collect(toImmutableList()));
 
     case SARG:
@@ -2052,17 +2051,16 @@ public abstract class SqlImplementor {
      * equivalent to "SELECT * FROM emp AS emp".) */
     public SqlNode asFrom() {
       if (neededAlias != null) {
+        final SqlIdentifier id = new SqlIdentifier(neededAlias, POS);
         if (node.getKind() == SqlKind.AS) {
           // If we already have an AS node, we need to replace the alias
           // This is especially relevant for the VALUES clause rendering
           SqlCall sqlCall = (SqlCall) node;
-          @SuppressWarnings("assignment.type.incompatible")
-          SqlNode[] operands = sqlCall.getOperandList().toArray(new SqlNode[0]);
-          operands[1] = new SqlIdentifier(neededAlias, POS);
+          List<SqlNode> operands = new ArrayList<>(sqlCall.getOperandList());
+          operands.set(1, id);
           return SqlStdOperatorTable.AS.createCall(POS, operands);
         } else {
-          return SqlStdOperatorTable.AS.createCall(POS, node,
-              new SqlIdentifier(neededAlias, POS));
+          return SqlStdOperatorTable.AS.createCall(POS, node, id);
         }
       }
       return node;
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java b/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java
index 56e224572c..865f047a4f 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java
@@ -211,11 +211,14 @@ public final class AggregateExpandDistinctAggregatesRule
     }
 
     // If only one distinct aggregate and one or more non-distinct aggregates,
-    // we can generate multi-phase aggregates
+    // we can generate multiphase aggregates
     if (distinctAggCalls.size() == 1 // one distinct aggregate
-        && filterCount == 0 // no filter
-        && unsupportedNonDistinctAggCallCount == 0 // sum/min/max/count in non-distinct aggregate
-        && nonDistinctAggCalls.size() > 0) { // one or more non-distinct aggregates
+        // no filter
+        && filterCount == 0
+        // sum/min/max/count in non-distinct aggregate
+        && unsupportedNonDistinctAggCallCount == 0
+        // one or more non-distinct aggregates
+        && !nonDistinctAggCalls.isEmpty()) {
       final RelBuilder relBuilder = call.builder();
       convertSingletonDistinct(relBuilder, aggregate, distinctCallArgLists);
       call.transformTo(relBuilder.build());
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandWithinDistinctRule.java b/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandWithinDistinctRule.java
index cf5aafca48..50f43771db 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandWithinDistinctRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandWithinDistinctRule.java
@@ -44,7 +44,6 @@ import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.function.IntPredicate;
@@ -55,6 +54,8 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
 import static org.apache.calcite.rel.rules.AggregateExpandDistinctAggregatesRule.groupValue;
 import static org.apache.calcite.rel.rules.AggregateExpandDistinctAggregatesRule.remap;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Planner rule that rewrites an {@link Aggregate} that contains
  * {@code WITHIN DISTINCT} aggregate functions.
@@ -248,7 +249,7 @@ public class AggregateExpandWithinDistinctRule
       }
 
       int field(int field, int filterArg) {
-        return Objects.requireNonNull(args.get(IntPair.of(field, filterArg)));
+        return requireNonNull(args.get(IntPair.of(field, filterArg)));
       }
 
       /** Computes an aggregate call argument's values for a
@@ -311,7 +312,7 @@ public class AggregateExpandWithinDistinctRule
       }
 
       int getAgg(int i) {
-        return Objects.requireNonNull(aggs.get(i));
+        return requireNonNull(aggs.get(i));
       }
 
       /** Registers an extra {@code COUNT} aggregate call when it's needed to
@@ -338,7 +339,7 @@ public class AggregateExpandWithinDistinctRule
       }
 
       int getCount(int filterArg) {
-        return Objects.requireNonNull(counts.get(filterArg));
+        return requireNonNull(counts.get(filterArg));
       }
     }
 
@@ -447,7 +448,7 @@ public class AggregateExpandWithinDistinctRule
           }
         }
       }
-      if (filters.size() > 0) {
+      if (!filters.isEmpty()) {
         aggCall = aggCall.filter(b.and(filters));
       }
       aggCalls.add(aggCall);
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/AggregateMergeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/AggregateMergeRule.java
index 36a3bf54d5..34b727e222 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateMergeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateMergeRule.java
@@ -106,7 +106,7 @@ public class AggregateMergeRule
     final List<AggregateCall> finalCalls = new ArrayList<>();
     for (AggregateCall topCall : topAgg.getAggCallList()) {
       if (!isAggregateSupported(topCall)
-          || topCall.getArgList().size() == 0) {
+          || topCall.getArgList().isEmpty()) {
         return;
       }
       // Make sure top aggregate argument refers to one of the aggregate
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/AggregateReduceFunctionsRule.java b/core/src/main/java/org/apache/calcite/rel/rules/AggregateReduceFunctionsRule.java
index ec09c77c47..ec40844ab2 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateReduceFunctionsRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateReduceFunctionsRule.java
@@ -53,11 +53,12 @@ import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Set;
 import java.util.function.IntPredicate;
 import java.util.function.Predicate;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Planner rule that reduces aggregate functions in
  * {@link org.apache.calcite.rel.core.Aggregate}s to simpler forms.
@@ -148,7 +149,8 @@ public class AggregateReduceFunctionsRule
         .as(Config.class)
         .withOperandFor(aggregateClass)
         // reduce specific functions provided by the client
-        .withFunctionsToReduce(Objects.requireNonNull(functionsToReduce, "functionsToReduce")));
+        .withFunctionsToReduce(
+            requireNonNull(functionsToReduce, "functionsToReduce")));
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java b/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java
index 2e7699a89d..fde19567e8 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java
@@ -43,6 +43,7 @@ import org.apache.calcite.util.graph.DefaultEdge;
 import org.apache.calcite.util.graph.DirectedGraph;
 import org.apache.calcite.util.graph.TopologicalOrderIterator;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.primitives.Ints;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
@@ -58,6 +59,8 @@ import java.util.Set;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static org.apache.calcite.util.Util.isDistinct;
+
 /**
  * CalcRelSplitter operates on a
  * {@link org.apache.calcite.rel.core.Calc} with multiple {@link RexCall}
@@ -87,7 +90,7 @@ public abstract class CalcRelSplitter {
   protected final RexProgram program;
   private final RelDataTypeFactory typeFactory;
 
-  private final RelType[] relTypes;
+  private final List<RelType> relTypes;
   private final RelOptCluster cluster;
   private final RelTraitSet traits;
   private final RelNode child;
@@ -104,19 +107,13 @@ public abstract class CalcRelSplitter {
    */
   CalcRelSplitter(Calc calc, RelBuilder relBuilder, RelType[] relTypes) {
     this.relBuilder = relBuilder;
-    for (int i = 0; i < relTypes.length; i++) {
-      assert relTypes[i] != null;
-      for (int j = 0; j < i; j++) {
-        assert relTypes[i] != relTypes[j]
-            : "Rel types must be distinct";
-      }
-    }
     this.program = calc.getProgram();
     this.cluster = calc.getCluster();
     this.traits = calc.getTraitSet();
     this.typeFactory = calc.getCluster().getTypeFactory();
     this.child = calc.getInput();
-    this.relTypes = relTypes;
+    this.relTypes = ImmutableList.copyOf(relTypes);
+    checkArgument(isDistinct(this.relTypes));
   }
 
   //~ Methods ----------------------------------------------------------------
@@ -201,7 +198,7 @@ public abstract class CalcRelSplitter {
         projectExprOrdinals = Ints.toArray(projectExprOrdinalList);
       }
 
-      final RelType relType = relTypes[levelTypeOrdinals[level]];
+      final RelType relType = relTypes.get(levelTypeOrdinals[level]);
 
       // Can we do the condition this level?
       int conditionExprOrdinal = -1;
@@ -275,7 +272,7 @@ public abstract class CalcRelSplitter {
 
     int levelCount = 0;
     final MaxInputFinder maxInputFinder = new MaxInputFinder(exprLevels);
-    boolean[] relTypesPossibleForTopLevel = new boolean[relTypes.length];
+    boolean[] relTypesPossibleForTopLevel = new boolean[relTypes.size()];
     Arrays.fill(relTypesPossibleForTopLevel, true);
 
     // Compute the order in which to visit expressions.
@@ -322,14 +319,12 @@ public abstract class CalcRelSplitter {
         if (level >= levelCount) {
           // This is a new level. We can use any type we like.
           for (int relTypeOrdinal = 0;
-              relTypeOrdinal < relTypes.length;
+              relTypeOrdinal < relTypes.size();
               relTypeOrdinal++) {
             if (!relTypesPossibleForTopLevel[relTypeOrdinal]) {
               continue;
             }
-            if (relTypes[relTypeOrdinal].canImplement(
-                expr,
-                condition)) {
+            if (relTypes.get(relTypeOrdinal).canImplement(expr, condition)) {
               // Success. We have found a type where we can
               // implement this expression.
               exprLevels[i] = level;
@@ -348,13 +343,11 @@ public abstract class CalcRelSplitter {
 
               // Successive reltypes may be possible.
               for (int j = relTypeOrdinal + 1;
-                  j < relTypes.length;
+                  j < relTypes.size();
                   ++j) {
                 if (relTypesPossibleForTopLevel[j]) {
                   relTypesPossibleForTopLevel[j] =
-                      relTypes[j].canImplement(
-                          expr,
-                          condition);
+                      relTypes.get(j).canImplement(expr, condition);
                 }
               }
 
@@ -370,7 +363,7 @@ public abstract class CalcRelSplitter {
           // None of the reltypes still active for this level could
           // implement expr. But maybe we could succeed with a new
           // level, with all options open?
-          if (count(relTypesPossibleForTopLevel) >= relTypes.length) {
+          if (count(relTypesPossibleForTopLevel) >= relTypes.size()) {
             // Cannot implement for any type.
             throw new AssertionError("cannot implement " + expr);
           }
@@ -380,9 +373,7 @@ public abstract class CalcRelSplitter {
           Arrays.fill(relTypesPossibleForTopLevel, true);
         } else {
           final int levelTypeOrdinal = levelTypeOrdinals[level];
-          if (!relTypes[levelTypeOrdinal].canImplement(
-              expr,
-              condition)) {
+          if (!relTypes.get(levelTypeOrdinal).canImplement(expr, condition)) {
             // Cannot implement this expression in this type;
             // continue to next level.
             continue;
@@ -395,9 +386,10 @@ public abstract class CalcRelSplitter {
     if (levelCount > 0) {
       // The latest level should be CalcRelType otherwise literals cannot be
       // implemented.
-      assert "CalcRelType".equals(relTypes[0].name)
-          : "The first RelType should be CalcRelType for proper RexLiteral"
-          + " implementation at the last level, got " + relTypes[0].name;
+      final String name = relTypes.get(0).name;
+      checkArgument(name.equals("CalcRelType"),
+          "The first RelType should be CalcRelType for proper RexLiteral"
+              + " implementation at the last level, got %s", name);
       if (levelTypeOrdinals[levelCount - 1] != 0) {
         levelCount++;
       }
@@ -598,12 +590,10 @@ public abstract class CalcRelSplitter {
       outputRowType =
           RexUtil.createStructType(typeFactory, projectRefs, fieldNames, null);
     }
-    final RexProgram program =
-        new RexProgram(
-            inputRowType, exprs, projectRefs, conditionRef, outputRowType);
     // Program is NOT normalized here (e.g. can contain literals in
     // call operands), since literals should be inlined.
-    return program;
+    return new RexProgram(inputRowType, exprs, projectRefs, conditionRef,
+        outputRowType);
   }
 
   private String deriveFieldName(RexNode expr, int ordinal) {
@@ -637,11 +627,11 @@ public abstract class CalcRelSplitter {
     StringWriter traceMsg = new StringWriter();
     PrintWriter traceWriter = new PrintWriter(traceMsg);
     traceWriter.println("FarragoAutoCalcRule result expressions for: ");
-    traceWriter.println(program.toString());
+    traceWriter.println(program);
 
     for (int level = 0; level < levelCount; level++) {
       traceWriter.println("Rel Level " + level
-          + ", type " + relTypes[levelTypeOrdinals[level]]);
+          + ", type " + relTypes.get(levelTypeOrdinals[level]));
 
       for (int i = 0; i < exprs.length; i++) {
         RexNode expr = exprs[i];
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java b/core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java
index f9b64bc1ce..ef69a41189 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java
@@ -111,18 +111,15 @@ public abstract class FilterJoinRule<C extends FilterJoinRule.Config>
     // Try to push down above filters. These are typically where clause
     // filters. They can be pushed down if they are not on the NULL
     // generating side.
-    boolean filterPushed = false;
-    if (RelOptUtil.classifyFilters(
-        join,
-        aboveFilters,
-        joinType.canPushIntoFromAbove(),
-        joinType.canPushLeftFromAbove(),
-        joinType.canPushRightFromAbove(),
-        joinFilters,
-        leftFilters,
-        rightFilters)) {
-      filterPushed = true;
-    }
+    boolean filterPushed =
+        RelOptUtil.classifyFilters(join,
+            aboveFilters,
+            joinType.canPushIntoFromAbove(),
+            joinType.canPushLeftFromAbove(),
+            joinType.canPushRightFromAbove(),
+            joinFilters,
+            leftFilters,
+            rightFilters);
 
     // Move join filters up if needed
     validateJoinFilters(aboveFilters, joinFilters, join, joinType);
@@ -352,7 +349,7 @@ public abstract class FilterJoinRule<C extends FilterJoinRule.Config>
         }
       }
       // Only need one equal condition for each equal set.
-      if (leftSet.size() > 0 && rightSet.size() > 0) {
+      if (!leftSet.isEmpty() && !rightSet.isEmpty()) {
         result.add(
             rexBuilder.makeCall(SqlStdOperatorTable.EQUALS,
                 leftSet.get(0),
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinAddRedundantSemiJoinRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinAddRedundantSemiJoinRule.java
index c01f56b6c2..3474a724d7 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinAddRedundantSemiJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinAddRedundantSemiJoinRule.java
@@ -74,7 +74,7 @@ public class JoinAddRedundantSemiJoinRule
 
     // determine if we have a valid join condition
     final JoinInfo joinInfo = origJoinRel.analyzeCondition();
-    if (joinInfo.leftKeys.size() == 0) {
+    if (joinInfo.leftKeys.isEmpty()) {
       return;
     }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinPushTransitivePredicatesRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinPushTransitivePredicatesRule.java
index b112e1d9d6..68db8a2a88 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinPushTransitivePredicatesRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinPushTransitivePredicatesRule.java
@@ -82,7 +82,7 @@ public class JoinPushTransitivePredicatesRule
     final RelBuilder relBuilder = call.builder();
 
     RelNode left = join.getLeft();
-    if (preds.leftInferredPredicates.size() > 0) {
+    if (!preds.leftInferredPredicates.isEmpty()) {
       RelNode curr = left;
       left = relBuilder.push(left)
           .filter(preds.leftInferredPredicates).build();
@@ -90,7 +90,7 @@ public class JoinPushTransitivePredicatesRule
     }
 
     RelNode right = join.getRight();
-    if (preds.rightInferredPredicates.size() > 0) {
+    if (!preds.rightInferredPredicates.isEmpty()) {
       RelNode curr = right;
       right = relBuilder.push(right)
           .filter(preds.rightInferredPredicates).build();
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java
index c07b8ea302..8de5032bbe 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java
@@ -40,6 +40,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 import org.immutables.value.Value;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -289,7 +290,7 @@ public class JoinToMultiJoinRule
             null,
             null);
       } else {
-        joinSpecs.add(Pair.of(JoinRelType.INNER, (@Nullable RexNode) null));
+        joinSpecs.add(Pair.of(JoinRelType.INNER, null));
       }
       joinSpecs.add(Pair.of(joinType, joinRel.getCondition()));
       break;
@@ -303,7 +304,7 @@ public class JoinToMultiJoinRule
             right.getRowType().getFieldList(),
             joinRel.getRowType().getFieldList());
       } else {
-        joinSpecs.add(Pair.of(JoinRelType.INNER, (RexNode) null));
+        joinSpecs.add(Pair.of(JoinRelType.INNER, null));
       }
       break;
     default:
@@ -315,7 +316,7 @@ public class JoinToMultiJoinRule
             null,
             null);
       } else {
-        joinSpecs.add(Pair.of(JoinRelType.INNER, (RexNode) null));
+        joinSpecs.add(Pair.of(JoinRelType.INNER, null));
       }
       if (rightCombined) {
         copyOuterJoinInfo(
@@ -325,7 +326,7 @@ public class JoinToMultiJoinRule
             right.getRowType().getFieldList(),
             joinRel.getRowType().getFieldList());
       } else {
-        joinSpecs.add(Pair.of(JoinRelType.INNER, (RexNode) null));
+        joinSpecs.add(Pair.of(JoinRelType.INNER, null));
       }
     }
   }
@@ -358,15 +359,11 @@ public class JoinToMultiJoinRule
     if (adjustmentAmount == 0) {
       destJoinSpecs.addAll(srcJoinSpecs);
     } else {
-      assert srcFields != null;
-      assert destFields != null;
-      int nFields = srcFields.size();
-      int[] adjustments = new int[nFields];
-      for (int idx = 0; idx < nFields; idx++) {
-        adjustments[idx] = adjustmentAmount;
-      }
-      for (Pair<JoinRelType, @Nullable RexNode> src
-          : srcJoinSpecs) {
+      requireNonNull(srcFields, "srcFields");
+      requireNonNull(destFields, "destFields");
+      int[] adjustments = new int[srcFields.size()];
+      Arrays.fill(adjustments, adjustmentAmount);
+      for (Pair<JoinRelType, @Nullable RexNode> src : srcJoinSpecs) {
         destJoinSpecs.add(
             Pair.of(
                 src.left,
@@ -457,9 +454,7 @@ public class JoinToMultiJoinRule
     int nFieldsOnLeft = left.getRowType().getFieldList().size();
     int nFieldsOnRight = right.getRowType().getFieldList().size();
     int[] adjustments = new int[nFieldsOnRight];
-    for (int i = 0; i < nFieldsOnRight; i++) {
-      adjustments[i] = nFieldsOnLeft;
-    }
+    Arrays.fill(adjustments, nFieldsOnLeft);
     rightFilter =
         rightFilter.accept(
             new RelOptUtil.RexInputConverter(
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/LoptJoinTree.java b/core/src/main/java/org/apache/calcite/rel/rules/LoptJoinTree.java
index d5081273a6..dc991a8c6f 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/LoptJoinTree.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/LoptJoinTree.java
@@ -24,7 +24,8 @@ import org.checkerframework.checker.initialization.qual.UnderInitialization;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Utility class used to store a {@link org.apache.calcite.rel.core.Join} tree
@@ -198,8 +199,8 @@ public class LoptJoinTree {
 
     public Node(BinaryTree left, BinaryTree right, @UnderInitialization LoptJoinTree parent) {
       super(parent);
-      this.left = Objects.requireNonNull(left, "left");
-      this.right = Objects.requireNonNull(right, "right");
+      this.left = requireNonNull(left, "left");
+      this.right = requireNonNull(right, "right");
     }
 
     public BinaryTree getLeft() {
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/LoptMultiJoin.java b/core/src/main/java/org/apache/calcite/rel/rules/LoptMultiJoin.java
index 4182a120cb..1aa93d7b59 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/LoptMultiJoin.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/LoptMultiJoin.java
@@ -60,25 +60,25 @@ public class LoptMultiJoin {
   //~ Instance fields --------------------------------------------------------
 
   /** The MultiJoin being optimized. */
-  MultiJoin multiJoin;
+  final MultiJoin multiJoin;
 
   /**
    * Join filters associated with the MultiJoin, decomposed into a list.
    * Excludes left/right outer join filters.
    */
-  private List<RexNode> joinFilters;
+  private final List<RexNode> joinFilters;
 
   /**
    * All join filters associated with the MultiJoin, decomposed into a
    * list. Includes left/right outer join filters.
    */
-  private List<RexNode> allJoinFilters;
+  private final List<RexNode> allJoinFilters;
 
   /** Number of factors into the MultiJoin. */
   private final int nJoinFactors;
 
   /** Total number of fields in the MultiJoin. */
-  private int nTotalFields;
+  private final int nTotalFields;
 
   /** Original inputs into the MultiJoin. */
   private final ImmutableList<RelNode> joinFactors;
@@ -102,7 +102,7 @@ public class LoptMultiJoin {
    * row scan processing has completed. This excludes fields referenced in
    * join conditions, unless the field appears in the final projection list.
    */
-  private List<@Nullable ImmutableBitSet> projFields;
+  private final List<@Nullable ImmutableBitSet> projFields;
 
   /**
    * Map containing reference counts of the fields referenced in join
@@ -111,7 +111,7 @@ public class LoptMultiJoin {
    * for reference counts instead of simply a bitmap.) The map is indexed by
    * the factor number.
    */
-  private Map<Integer, int[]> joinFieldRefCountsMap;
+  private final Map<Integer, int[]> joinFieldRefCountsMap;
 
   /**
    * For each join filter, associates a bitmap indicating all factors
@@ -128,12 +128,12 @@ public class LoptMultiJoin {
   /**
    * Starting RexInputRef index corresponding to each join factor.
    */
-  int [] joinStart;
+  final int [] joinStart;
 
   /**
    * Number of fields in each join factor.
    */
-  int [] nFieldsInJoinFactor;
+  final int [] nFieldsInJoinFactor;
 
   /**
    * Bitmap indicating which factors each factor references in join filters
@@ -158,18 +158,18 @@ public class LoptMultiJoin {
    * semijoin that allows the factor to be removed. If the factor cannot be
    * removed, the entry corresponding to the factor is null.
    */
-  @Nullable Integer [] joinRemovalFactors;
+  final @Nullable Integer [] joinRemovalFactors;
 
   /**
    * The semijoins that allow the join of a dimension table to be removed.
    */
-  LogicalJoin[] joinRemovalSemiJoins;
+  final LogicalJoin[] joinRemovalSemiJoins;
 
   /**
    * Set of null-generating factors whose corresponding outer join can be
    * removed from the query plan.
    */
-  Set<Integer> removableOuterJoinFactors;
+  final Set<Integer> removableOuterJoinFactors;
 
   /**
    * Map consisting of all pairs of self-joins where the self-join can be
@@ -177,7 +177,7 @@ public class LoptMultiJoin {
    * join on the same set of unique keys. The map is keyed by either factor in
    * the self join.
    */
-  Map<Integer, RemovableSelfJoin> removableSelfJoinPairs;
+  final Map<Integer, RemovableSelfJoin> removableSelfJoinPairs;
 
   //~ Constructors -----------------------------------------------------------
 
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/LoptOptimizeJoinRule.java b/core/src/main/java/org/apache/calcite/rel/rules/LoptOptimizeJoinRule.java
index 0ae3e76e58..48b129aaaa 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/LoptOptimizeJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/LoptOptimizeJoinRule.java
@@ -335,19 +335,15 @@ public class LoptOptimizeJoinRule
       for (RexNode filter : multiJoin.getJoinFilters()) {
         ImmutableBitSet joinFactors =
             multiJoin.getFactorsRefByJoinFilter(filter);
-        if ((joinFactors.cardinality() == 2)
+        if (joinFactors.cardinality() == 2
             && joinFactors.get(factor1)
             && joinFactors.get(factor2)) {
           selfJoinFilters.add(filter);
         }
       }
-      if ((selfJoinFilters.size() > 0)
-          && isSelfJoinFilterUnique(
-            mq,
-            multiJoin,
-            factor1,
-            factor2,
-            selfJoinFilters)) {
+      if (!selfJoinFilters.isEmpty()
+          && isSelfJoinFilterUnique(mq, multiJoin, factor1, factor2,
+              selfJoinFilters)) {
         multiJoin.addRemovableSelfJoinPair(factor1, factor2);
       }
     }
@@ -754,7 +750,7 @@ public class LoptOptimizeJoinRule
       prevFactor = nextFactor;
     }
 
-    assert filtersToAdd.size() == 0;
+    assert filtersToAdd.isEmpty();
     return joinTree;
   }
 
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java b/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java
index 0ddebb8ac4..724884641d 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java
@@ -74,7 +74,7 @@ public class LoptSemiJoinOptimizer {
    * Semijoins corresponding to each join factor, if they are going to be
    * filtered by semijoins. Otherwise, the entry is the original join factor.
    */
-  private RelNode [] chosenSemiJoins;
+  private final RelNode [] chosenSemiJoins;
 
   /**
    * Associates potential semijoins with each fact table factor. The first
@@ -265,7 +265,7 @@ public class LoptSemiJoinOptimizer {
     RelNode factRel = multiJoin.getJoinFactor(factIdx);
     RelNode dimRel = multiJoin.getJoinFactor(dimIdx);
     final JoinInfo joinInfo = JoinInfo.of(factRel, dimRel, semiJoinCondition);
-    assert joinInfo.leftKeys.size() > 0;
+    assert !joinInfo.leftKeys.isEmpty();
 
     // mutable copies
     final List<Integer> leftKeys = Lists.newArrayList(joinInfo.leftKeys);
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java b/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java
index e502e8c54c..d636d23fab 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java
@@ -46,11 +46,12 @@ import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Objects;
 
 import static org.apache.calcite.rel.rules.LoptMultiJoin.Edge;
 import static org.apache.calcite.util.mapping.Mappings.TargetMapping;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Planner rule that finds an approximately optimal ordering for join operators
  * using a heuristic algorithm.
@@ -398,7 +399,7 @@ public class MultiJoinOptimizeBushyRule
       super(id, factors, cost);
       this.leftFactor = leftFactor;
       this.rightFactor = rightFactor;
-      this.conditions = Objects.requireNonNull(conditions, "conditions");
+      this.conditions = requireNonNull(conditions, "conditions");
     }
 
     @Override public String toString() {
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectTableScanRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectTableScanRule.java
index 9257bbe98c..770860cc4a 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectTableScanRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectTableScanRule.java
@@ -41,6 +41,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Planner rule that converts a {@link Project}
  * on a {@link org.apache.calcite.rel.core.TableScan}
@@ -102,7 +104,7 @@ public class ProjectTableScanRule
 
   protected void apply(RelOptRuleCall call, Project project, TableScan scan) {
     final RelOptTable table = scan.getTable();
-    assert table.unwrap(ProjectableFilterableTable.class) != null;
+    requireNonNull(table.unwrap(ProjectableFilterableTable.class));
 
     final List<Integer> selectedColumns = new ArrayList<>();
     final RexVisitorImpl<Void> visitor = new RexVisitorImpl<Void>(true) {
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java b/core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java
index 48b37ca74f..a201f8f870 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java
@@ -52,6 +52,8 @@ import java.util.function.Predicate;
 
 import static com.google.common.collect.Iterables.concat;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Collection of rules which remove sections of a query plan known never to
  * produce any rows.
@@ -389,8 +391,7 @@ public abstract class PruneEmptyRules {
       return new PruneEmptyRule(this) {
         @Override public void onMatch(RelOptRuleCall call) {
           final Union union = call.rel(0);
-          final List<RelNode> inputs = union.getInputs();
-          assert inputs != null;
+          final List<RelNode> inputs = requireNonNull(union.getInputs());
           final RelBuilder relBuilder = call.builder();
           int nonEmptyInputs = 0;
           for (RelNode input : inputs) {
@@ -427,8 +428,7 @@ public abstract class PruneEmptyRules {
       return new PruneEmptyRule(this) {
         @Override public void onMatch(RelOptRuleCall call) {
           final Minus minus = call.rel(0);
-          final List<RelNode> inputs = minus.getInputs();
-          assert inputs != null;
+          final List<RelNode> inputs = requireNonNull(minus.getInputs());
           int nonEmptyInputs = 0;
           final RelBuilder relBuilder = call.builder();
           for (RelNode input : inputs) {
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java b/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java
index d3717d6cb6..20310a95c9 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java
@@ -343,7 +343,7 @@ public class PushProjector {
     // special expressions to preserve in the projection; otherwise,
     // there's no point in proceeding any further
     if (origProj == null) {
-      if (childPreserveExprs.size() == 0) {
+      if (childPreserveExprs.isEmpty()) {
         return null;
       }
 
@@ -355,16 +355,15 @@ public class PushProjector {
         projRefs.set(0, nChildFields);
       }
       nProject = nChildFields;
-    } else if (
-        (projRefs.cardinality() == nChildFields)
-            && (childPreserveExprs.size() == 0)) {
+    } else if (projRefs.cardinality() == nChildFields
+        && childPreserveExprs.isEmpty()) {
       return null;
     }
 
     // if nothing is being selected from the underlying rel, just
     // project the default expression passed in as a parameter or the
     // first column if there is no default expression
-    if ((projRefs.cardinality() == 0) && (childPreserveExprs.size() == 0)) {
+    if (projRefs.cardinality() == 0 && childPreserveExprs.isEmpty()) {
       if (defaultExpr != null) {
         childPreserveExprs.add(defaultExpr);
       } else if (nChildFields == 1) {
@@ -459,12 +458,12 @@ public class PushProjector {
       // if nothing is projected from the children, arbitrarily project
       // the first columns; this is necessary since Fennel doesn't
       // handle 0-column projections
-      if ((nProject == 0) && (childPreserveExprs.size() == 0)) {
+      if (nProject == 0 && childPreserveExprs.isEmpty()) {
         projRefs.set(0);
         nProject = 1;
       }
       if (childRel instanceof Join) {
-        if ((nRightProject == 0) && (rightPreserveExprs.size() == 0)) {
+        if (nRightProject == 0 && rightPreserveExprs.isEmpty()) {
           projRefs.set(nFields);
           nRightProject = 1;
         }
@@ -475,14 +474,11 @@ public class PushProjector {
     // referenced and there are no special preserve expressions; note
     // that we need to do this check after we've handled the 0-column
     // project cases
-    boolean allFieldsReferenced = IntStream.range(0, nChildFields).allMatch(i -> projRefs.get(i));
-    if (allFieldsReferenced
-        && childPreserveExprs.size() == 0
-        && rightPreserveExprs.size() == 0) {
-      return true;
-    }
-
-    return false;
+    boolean allFieldsReferenced =
+        IntStream.range(0, nChildFields).allMatch(projRefs::get);
+    return allFieldsReferenced
+        && childPreserveExprs.isEmpty()
+        && rightPreserveExprs.isEmpty();
   }
 
   /**
@@ -535,7 +531,7 @@ public class PushProjector {
     // add on the expressions that need to be preserved, converting the
     // arguments to reference the projected columns (if necessary)
     int[] adjustments = {};
-    if ((preserveExprs.size() > 0) && adjust) {
+    if (!preserveExprs.isEmpty() && adjust) {
       adjustments = new int[childFields.size()];
       for (int idx = offset; idx < childFields.size(); idx++) {
         adjustments[idx] = -offset;
@@ -556,8 +552,11 @@ public class PushProjector {
         newExpr = projExpr;
       }
 
-      List<RelDataType> typeList = projChild.getRowType().getFieldList()
-          .stream().map(field -> field.getType()).collect(Collectors.toList());
+      List<RelDataType> typeList =
+          projChild.getRowType().getFieldList()
+              .stream()
+              .map(RelDataTypeField::getType)
+              .collect(Collectors.toList());
       RexUtil.FixNullabilityShuttle fixer =
           new RexUtil.FixNullabilityShuttle(
               projChild.getCluster().getRexBuilder(), typeList);
@@ -742,7 +741,7 @@ public class PushProjector {
             return true;
           } else if (requireNonNull(rightFields, "rightFields").contains(exprArgs)
               && isStrong(exprArgs, call)) {
-            assert preserveRight != null;
+            requireNonNull(preserveRight, "preserveRight");
             if (!preserveRight.contains(call)) {
               preserveRight.add(call);
             }
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java
index 42d8403dbc..e68cc2902b 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java
@@ -220,11 +220,10 @@ public class ReduceDecimalsRule
    * Maps a RexCall to a RexExpander.
    */
   private static class ExpanderMap {
-    private final Map<SqlOperator, RexExpander> map;
-    private RexExpander defaultExpander;
+    private final Map<SqlOperator, RexExpander> map = new HashMap<>();
+    private final RexExpander defaultExpander;
 
     private ExpanderMap(RexBuilder rexBuilder) {
-      map = new HashMap<>();
       defaultExpander = new CastArgAsDoubleExpander(rexBuilder);
       registerExpanders(map, rexBuilder);
     }
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java
index 7910c6d684..f6917e22ae 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java
@@ -44,7 +44,8 @@ import com.google.common.collect.ImmutableMap;
 import org.immutables.value.Value;
 
 import java.util.Map;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Planner rule that pushes
@@ -131,7 +132,7 @@ public class SortProjectTransposeRule
       if (node.isA(SqlKind.CAST)) {
         // Check whether it is a monotonic preserving cast, otherwise we cannot push
         final RexCall cast = (RexCall) node;
-        RelFieldCollation newFc = Objects.requireNonNull(RexUtil.apply(map, fc));
+        RelFieldCollation newFc = requireNonNull(RexUtil.apply(map, fc));
         final RexCallBinding binding =
             RexCallBinding.create(cluster.getTypeFactory(), cast,
                 ImmutableList.of(RelCollations.of(newFc)));
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRedundantRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRedundantRule.java
index 766849a443..bf1871cbbb 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRedundantRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRedundantRule.java
@@ -127,7 +127,7 @@ public class SortRemoveRedundantRule
     }
   }
 
-  private Optional<Integer> getRowCountThreshold(Sort sort) {
+  private static Optional<Integer> getRowCountThreshold(Sort sort) {
     if (RelOptUtil.isLimit(sort)) {
       final int fetch =
           sort.fetch instanceof RexLiteral ? RexLiteral.intValue(sort.fetch) : 0;
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java
index 46ac70f147..6feee83c76 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java
@@ -51,12 +51,13 @@ import org.immutables.value.Value;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 import java.util.Set;
 import java.util.stream.Collectors;
 
 import static org.apache.calcite.util.Util.last;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Transform that converts IN, EXISTS and scalar sub-queries into joins.
  *
@@ -79,7 +80,7 @@ public class SubQueryRemoveRule
   /** Creates a SubQueryRemoveRule. */
   protected SubQueryRemoveRule(Config config) {
     super(config);
-    Objects.requireNonNull(config.matchHandler());
+    requireNonNull(config.matchHandler());
   }
 
   @Override public void onMatch(RelOptRuleCall call) {
@@ -830,8 +831,7 @@ public class SubQueryRemoveRule
     final Project project = call.rel(0);
     final RelBuilder builder = call.builder();
     final RexSubQuery e =
-        RexUtil.SubQueryFinder.find(project.getProjects());
-    assert e != null;
+        requireNonNull(RexUtil.SubQueryFinder.find(project.getProjects()));
     final RelOptUtil.Logic logic =
         LogicVisitor.find(RelOptUtil.Logic.TRUE_FALSE_UNKNOWN,
             project.getProjects(), e);
@@ -887,8 +887,7 @@ public class SubQueryRemoveRule
     final Join join = call.rel(0);
     final RelBuilder builder = call.builder();
     final RexSubQuery e =
-        RexUtil.SubQueryFinder.find(join.getCondition());
-    assert e != null;
+        requireNonNull(RexUtil.SubQueryFinder.find(join.getCondition()));
     final RelOptUtil.Logic logic =
         LogicVisitor.find(RelOptUtil.Logic.TRUE,
             ImmutableList.of(join.getCondition()), e);
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java
index 488e10fe9c..3b8d03e57c 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java
@@ -45,6 +45,8 @@ import org.slf4j.Logger;
 import java.util.ArrayList;
 import java.util.List;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 import static java.util.Objects.requireNonNull;
 
 /**
@@ -132,8 +134,8 @@ public class ValuesReduceRule
    */
   protected void apply(RelOptRuleCall call, @Nullable LogicalProject project,
       @Nullable LogicalFilter filter, LogicalValues values) {
-    assert values != null;
-    assert filter != null || project != null;
+    requireNonNull(values, "values");
+    checkArgument(filter != null || project != null);
     final RexNode conditionExpr =
         (filter == null) ? null : filter.getCondition();
     final List<RexNode> projectExprs =
diff --git a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactory.java b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactory.java
index ecbde3db8d..9821451b9a 100644
--- a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactory.java
+++ b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactory.java
@@ -31,7 +31,8 @@ import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * RelDataTypeFactory is a factory for datatype descriptors. It defines methods
@@ -468,7 +469,7 @@ public interface RelDataTypeFactory {
      * Creates a Builder with the given type factory.
      */
     public Builder(RelDataTypeFactory typeFactory) {
-      this.typeFactory = Objects.requireNonNull(typeFactory, "typeFactory");
+      this.typeFactory = requireNonNull(typeFactory, "typeFactory");
     }
 
     /**
diff --git a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java
index 805b1cc9f3..d74e876240 100644
--- a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java
+++ b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java
@@ -136,10 +136,9 @@ public abstract class RelDataTypeFactoryImpl implements RelDataTypeFactory {
     return canonize(javaType);
   }
 
-  // implement RelDataTypeFactory
   @Override public RelDataType createJoinType(RelDataType... types) {
-    assert types != null;
-    assert types.length >= 1;
+    requireNonNull(types, "types");
+    checkArgument(types.length >= 1);
     final List<RelDataType> flattenedTypes = new ArrayList<>();
     getTypeList(ImmutableList.copyOf(types), flattenedTypes);
     return canonize(
@@ -208,7 +207,7 @@ public abstract class RelDataTypeFactoryImpl implements RelDataTypeFactory {
       List<RelDataType> types, SqlTypeMappingRule mappingRule) {
     requireNonNull(types, "types");
     requireNonNull(mappingRule, "mappingRule");
-    checkArgument(types.size() >= 1, "types.size >= 1");
+    checkArgument(!types.isEmpty(), "!types.isEmpty");
     RelDataType type0 = types.get(0);
     if (type0.isStruct()) {
       return leastRestrictiveStructuredType(types);
@@ -571,8 +570,7 @@ public abstract class RelDataTypeFactoryImpl implements RelDataTypeFactory {
   /** Create decimal type equivalent with the given {@code type} while sans nullability. */
   private RelDataType decimalOf2(RelDataType type) {
     assert SqlTypeUtil.isNumeric(type) || SqlTypeUtil.isNull(type);
-    SqlTypeName typeName = type.getSqlTypeName();
-    assert typeName != null;
+    final SqlTypeName typeName = requireNonNull(type.getSqlTypeName());
     switch (typeName) {
     case DECIMAL:
       // Fix the precision when the type is JavaType.
@@ -620,8 +618,8 @@ public abstract class RelDataTypeFactoryImpl implements RelDataTypeFactory {
   public class JavaType extends RelDataTypeImpl {
     private final Class clazz;
     private final boolean nullable;
-    private @Nullable SqlCollation collation;
-    private @Nullable Charset charset;
+    private final @Nullable SqlCollation collation;
+    private final @Nullable Charset charset;
 
     public JavaType(Class clazz) {
       this(clazz, !clazz.isPrimitive());
@@ -642,8 +640,8 @@ public abstract class RelDataTypeFactoryImpl implements RelDataTypeFactory {
       super(fieldsOf(clazz));
       this.clazz = clazz;
       this.nullable = nullable;
-      assert (charset != null) == SqlTypeUtil.inCharFamily(this)
-          : "Need to be a chartype";
+      checkArgument((charset != null) == SqlTypeUtil.inCharFamily(this),
+          "Need to be a chartype");
       this.charset = charset;
       this.collation = collation;
       computeDigest();
diff --git a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java
index 9891ee304a..67ab341016 100644
--- a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java
+++ b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java
@@ -127,7 +127,7 @@ public abstract class RelDataTypeImpl
       }
     }
     // Extra field
-    if (fieldList.size() > 0) {
+    if (!fieldList.isEmpty()) {
       final RelDataTypeField lastField = Iterables.getLast(fieldList);
       if (lastField.getName().equals("_extra")) {
         return new RelDataTypeFieldImpl(
@@ -189,17 +189,23 @@ public abstract class RelDataTypeImpl
   }
 
   @Override public List<RelDataTypeField> getFieldList() {
-    assert fieldList != null : "fieldList must not be null, type = " + this;
+    if (fieldList == null) {
+      throw new AssertionError("fieldList must not be null, type = " + this);
+    }
     return fieldList;
   }
 
   @Override public List<String> getFieldNames() {
-    assert fieldList != null : "fieldList must not be null, type = " + this;
+    if (fieldList == null) {
+      throw new AssertionError("fieldList must not be null, type = " + this);
+    }
     return Pair.left(fieldList);
   }
 
   @Override public int getFieldCount() {
-    assert fieldList != null : "fieldList must not be null, type = " + this;
+    if (fieldList == null) {
+      throw new AssertionError("fieldList must not be null, type = " + this);
+    }
     return fieldList.size();
   }
 
@@ -229,7 +235,7 @@ public abstract class RelDataTypeImpl
   @Override public boolean equals(@Nullable Object obj) {
     return this == obj
         || obj instanceof RelDataTypeImpl
-          && Objects.equals(this.digest, ((RelDataTypeImpl) obj).digest);
+        && Objects.equals(this.digest, ((RelDataTypeImpl) obj).digest);
   }
 
   @Override public int hashCode() {
@@ -350,7 +356,7 @@ public abstract class RelDataTypeImpl
    * that copies a given type using the given type factory.
    */
   public static RelProtoDataType proto(final RelDataType protoType) {
-    assert protoType != null;
+    requireNonNull(protoType, "protoType");
     return typeFactory -> typeFactory.copyType(protoType);
   }
 
@@ -366,7 +372,7 @@ public abstract class RelDataTypeImpl
    */
   public static RelProtoDataType proto(final SqlTypeName typeName,
       final boolean nullable) {
-    assert typeName != null;
+    requireNonNull(typeName, "typeName");
     return typeFactory -> {
       final RelDataType type = typeFactory.createSqlType(typeName);
       return typeFactory.createTypeWithNullability(type, nullable);
@@ -386,7 +392,7 @@ public abstract class RelDataTypeImpl
    */
   public static RelProtoDataType proto(final SqlTypeName typeName,
       final int precision, final boolean nullable) {
-    assert typeName != null;
+    requireNonNull(typeName, "typeName");
     return typeFactory -> {
       final RelDataType type = typeFactory.createSqlType(typeName, precision);
       return typeFactory.createTypeWithNullability(type, nullable);
diff --git a/core/src/main/java/org/apache/calcite/rel/type/RelRecordType.java b/core/src/main/java/org/apache/calcite/rel/type/RelRecordType.java
index cd94c8f09d..4f253bf225 100644
--- a/core/src/main/java/org/apache/calcite/rel/type/RelRecordType.java
+++ b/core/src/main/java/org/apache/calcite/rel/type/RelRecordType.java
@@ -166,10 +166,10 @@ public class RelRecordType extends RelDataTypeImpl implements Serializable {
    * immutable list.
    */
   private static class SerializableRelRecordType implements Serializable {
-    private List<RelDataTypeField> fields;
+    private final List<RelDataTypeField> fields;
 
     private SerializableRelRecordType(List<RelDataTypeField> fields) {
-      this.fields = fields;
+      this.fields = requireNonNull(fields, "fields");
     }
 
     /**
diff --git a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
index 0814f474df..4c1e3d7cb4 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
@@ -424,9 +424,8 @@ public class RexBuilder {
             upperBound,
             rows,
             exclude);
-    final RexOver over =
+    RexNode result =
         new RexOver(type, operator, exprs, window, distinct, ignoreNulls);
-    RexNode result = over;
 
     // This should be correct but need time to go over test results.
     // Also want to look at combing with section below.
@@ -1066,8 +1065,7 @@ public class RexBuilder {
    * @param flag Flag value
    */
   public RexLiteral makeFlag(Enum flag) {
-    assert flag != null;
-    return makeLiteral(flag,
+    return makeLiteral(requireNonNull(flag, "flag"),
         typeFactory.createSqlType(SqlTypeName.SYMBOL),
         SqlTypeName.SYMBOL);
   }
@@ -1102,12 +1100,11 @@ public class RexBuilder {
           || !Objects.equals(nlsString.getCollation(), type.getCollation())) {
         assert type.getSqlTypeName() == SqlTypeName.CHAR
             || type.getSqlTypeName() == SqlTypeName.VARCHAR;
-        Charset charset = type.getCharset();
-        assert charset != null : "type.getCharset() must not be null";
-        assert type.getCollation() != null : "type.getCollation() must not be null";
-        o =
-            new NlsString(nlsString.getValue(), charset.name(),
-                type.getCollation());
+        Charset charset =
+            requireNonNull(type.getCharset(), "type.getCharset()");
+        final SqlCollation collation =
+            requireNonNull(type.getCollation(), "type.getCollation()");
+        o = new NlsString(nlsString.getValue(), charset.name(), collation);
       }
       break;
     case TIME:
@@ -1260,8 +1257,7 @@ public class RexBuilder {
    * Creates a character string literal.
    */
   public RexLiteral makeLiteral(String s) {
-    assert s != null;
-    return makePreciseStringLiteral(s);
+    return makePreciseStringLiteral(requireNonNull(s, "s"));
   }
 
   /**
@@ -1960,9 +1956,11 @@ public class RexBuilder {
       if (o instanceof NlsString) {
         return o;
       }
-      assert type.getCharset() != null : type + ".getCharset() must not be null";
-      return new NlsString((String) o, type.getCharset().name(),
-          type.getCollation());
+      final Charset charset = type.getCharset();
+      if (charset == null) {
+        throw new AssertionError(type + ".getCharset() must not be null");
+      }
+      return new NlsString((String) o, charset.name(), type.getCollation());
     case TIME:
       if (o instanceof TimeString) {
         return o;
diff --git a/core/src/main/java/org/apache/calcite/rex/RexCall.java b/core/src/main/java/org/apache/calcite/rex/RexCall.java
index 0d3b33a40d..b8089f775d 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexCall.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexCall.java
@@ -81,7 +81,6 @@ public class RexCall extends RexNode {
     this.op = requireNonNull(operator, "operator");
     this.operands = ImmutableList.copyOf(operands);
     this.nodeCount = RexUtil.nodeCount(1, this.operands);
-    assert operator.getKind() != null : operator;
     assert operator.validRexOperands(operands.size(), Litmus.THROW) : this;
     assert operator.kind != SqlKind.IN || this instanceof RexSubQuery;
   }
@@ -158,8 +157,8 @@ public class RexCall extends RexNode {
 
   protected String computeDigest(boolean withType) {
     final StringBuilder sb = new StringBuilder(op.getName());
-    if ((operands.size() == 0)
-        && (op.getSyntax() == SqlSyntax.FUNCTION_ID)) {
+    if (operands.isEmpty()
+        && op.getSyntax() == SqlSyntax.FUNCTION_ID) {
       // Don't print params for empty arg list. For example, we want
       // "SYSTEM_USER", not "SYSTEM_USER()".
     } else {
diff --git a/core/src/main/java/org/apache/calcite/rex/RexCorrelVariable.java b/core/src/main/java/org/apache/calcite/rex/RexCorrelVariable.java
index 101ca1c67b..c0ea81a485 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexCorrelVariable.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexCorrelVariable.java
@@ -24,6 +24,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.Objects;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Reference to the current row of a correlating relational expression.
  *
@@ -40,7 +42,7 @@ public class RexCorrelVariable extends RexVariable {
       CorrelationId id,
       RelDataType type) {
     super(id.getName(), type);
-    this.id = Objects.requireNonNull(id, "id");
+    this.id = requireNonNull(id, "id");
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexLambda.java b/core/src/main/java/org/apache/calcite/rex/RexLambda.java
index 8b43a7720e..2803b84b78 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexLambda.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexLambda.java
@@ -27,6 +27,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 import java.util.List;
 import java.util.Objects;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Represents a lambda expression.
  */
@@ -40,7 +42,7 @@ public class RexLambda extends RexNode {
 
   RexLambda(List<RexLambdaRef> parameters, RexNode expression) {
     this.parameters = ImmutableList.copyOf(parameters);
-    this.expression = Objects.requireNonNull(expression, "expression");
+    this.expression = requireNonNull(expression, "expression");
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
index 1e8cd76cd4..fd34c99674 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
@@ -652,11 +652,11 @@ public class RexLiteral extends RexNode {
       break;
     case BOOLEAN:
       assert value instanceof Boolean;
-      sb.append(value.toString());
+      sb.append(value);
       break;
     case DECIMAL:
       assert value instanceof BigDecimal;
-      sb.append(value.toString());
+      sb.append(value);
       break;
     case DOUBLE:
     case FLOAT:
@@ -666,7 +666,7 @@ public class RexLiteral extends RexNode {
     case BIGINT:
       assert value instanceof BigDecimal;
       long narrowLong = ((BigDecimal) value).longValue();
-      sb.append(String.valueOf(narrowLong));
+      sb.append(narrowLong);
       sb.append('L');
       break;
     case BINARY:
@@ -688,17 +688,17 @@ public class RexLiteral extends RexNode {
     case SYMBOL:
       assert value instanceof Enum;
       sb.append("FLAG(");
-      sb.append(value.toString());
+      sb.append(value);
       sb.append(")");
       break;
     case DATE:
       assert value instanceof DateString;
-      sb.append(value.toString());
+      sb.append(value);
       break;
     case TIME:
     case TIME_WITH_LOCAL_TIME_ZONE:
       assert value instanceof TimeString;
-      sb.append(value.toString());
+      sb.append(value);
       break;
     case TIME_TZ:
       assert value instanceof TimeWithTimeZoneString;
@@ -707,7 +707,7 @@ public class RexLiteral extends RexNode {
     case TIMESTAMP:
     case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
       assert value instanceof TimestampString;
-      sb.append(value.toString());
+      sb.append(value);
       break;
     case TIMESTAMP_TZ:
       assert value instanceof TimestampWithTimeZoneString;
@@ -727,7 +727,7 @@ public class RexLiteral extends RexNode {
     case INTERVAL_MINUTE_SECOND:
     case INTERVAL_SECOND:
       assert value instanceof BigDecimal;
-      sb.append(value.toString());
+      sb.append(value);
       break;
     case MULTISET:
     case ROW:
@@ -872,7 +872,7 @@ public class RexLiteral extends RexNode {
         break;
       default:
         // Allow fractional seconds for times and timestamps
-        assert format != null;
+        requireNonNull(format, "format");
         final DateTimeUtils.PrecisionTime ts =
             DateTimeUtils.parsePrecisionDateTimeLiteral(literal,
                 new SimpleDateFormat(format, Locale.ROOT), tz, -1);
@@ -1213,9 +1213,18 @@ public class RexLiteral extends RexNode {
     return findValue(node);
   }
 
-  public static int intValue(RexNode node) {
+  /** Returns the value of a literal, cast, or unary minus, as a number;
+   * never null. */
+  public static Number numberValue(RexNode node) {
     final Comparable value = castNonNull(findValue(node));
-    return ((Number) value).intValue();
+    return (Number) value;
+  }
+
+  /** Returns the value of a literal, cast, or unary minus, as an int;
+   * never null. */
+  public static int intValue(RexNode node) {
+    final Number number = numberValue(node);
+    return number.intValue();
   }
 
   public static @Nullable String stringValue(RexNode node) {
diff --git a/core/src/main/java/org/apache/calcite/rex/RexLocalRef.java b/core/src/main/java/org/apache/calcite/rex/RexLocalRef.java
index e3c0bc6388..81092bcd63 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexLocalRef.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexLocalRef.java
@@ -24,6 +24,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 import java.util.List;
 import java.util.Objects;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 /**
  * Local variable.
  *
@@ -52,8 +54,7 @@ public class RexLocalRef extends RexSlot {
    */
   public RexLocalRef(int index, RelDataType type) {
     super(createName(index), index, type);
-    assert type != null;
-    assert index >= 0;
+    checkArgument(index >= 0);
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexOver.java b/core/src/main/java/org/apache/calcite/rex/RexOver.java
index 792beae6a5..63a263e6b7 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexOver.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexOver.java
@@ -29,6 +29,8 @@ import java.util.Objects;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Call to an aggregate function over a window.
  */
@@ -71,7 +73,7 @@ public class RexOver extends RexCall {
       boolean ignoreNulls) {
     super(type, op, operands);
     checkArgument(op.isAggregator());
-    this.window = Objects.requireNonNull(window, "window");
+    this.window = requireNonNull(window, "window");
     this.distinct = distinct;
     this.ignoreNulls = ignoreNulls;
   }
diff --git a/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java b/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java
index 40d2c9a759..2c8cdfbd9a 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java
@@ -51,10 +51,8 @@ public class RexProgramBuilder {
   private final List<RexLocalRef> localRefList = new ArrayList<>();
   private final List<RexLocalRef> projectRefList = new ArrayList<>();
   private final List<@Nullable String> projectNameList = new ArrayList<>();
-  @SuppressWarnings("unused")
-  private final @Nullable RexSimplify simplify;
   private @Nullable RexLocalRef conditionRef = null;
-  private boolean validating;
+  private final boolean validating;
 
   //~ Constructors -----------------------------------------------------------
 
@@ -70,10 +68,9 @@ public class RexProgramBuilder {
    */
   @SuppressWarnings("method.invocation.invalid")
   private RexProgramBuilder(RelDataType inputRowType, RexBuilder rexBuilder,
-      @Nullable RexSimplify simplify) {
+      @Nullable RexSimplify unusedSimplify) {
     this.inputRowType = requireNonNull(inputRowType, "inputRowType");
     this.rexBuilder = requireNonNull(rexBuilder, "rexBuilder");
-    this.simplify = simplify; // may be null
     this.validating = assertionsAreEnabled();
 
     // Pre-create an expression for each input field.
@@ -272,7 +269,7 @@ public class RexProgramBuilder {
    * not, call {@link #registerOutput(RexNode)} first.
    */
   public void addCondition(RexNode expr) {
-    assert expr != null;
+    requireNonNull(expr, "expr");
     RexLocalRef conditionRef = this.conditionRef;
     if (conditionRef == null) {
       this.conditionRef = conditionRef = registerInput(expr);
@@ -660,8 +657,7 @@ public class RexProgramBuilder {
       }
       ref = (RexLocalRef) ref.accept(shuttle);
       this.projectRefList.add(ref);
-      final String name = outFields.get(i).getName();
-      assert name != null;
+      final String name = requireNonNull(outFields.get(i).getName());
       projectNameList.add(name);
     }
     if (conditionRef != null) {
@@ -1052,7 +1048,7 @@ public class RexProgramBuilder {
    * references.
    */
   private static class UpdateRefShuttle extends RexShuttle {
-    private List<RexLocalRef> newRefs;
+    private final List<RexLocalRef> newRefs;
 
     private UpdateRefShuttle(List<RexLocalRef> newRefs) {
       this.newRefs = newRefs;
diff --git a/core/src/main/java/org/apache/calcite/rex/RexShuttle.java b/core/src/main/java/org/apache/calcite/rex/RexShuttle.java
index 189cd8954b..e73766648a 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexShuttle.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexShuttle.java
@@ -26,8 +26,6 @@ import org.checkerframework.checker.nullness.qual.PolyNull;
 import java.util.ArrayList;
 import java.util.List;
 
-import static java.util.Objects.requireNonNull;
-
 /**
  * Passes over a row-expression, calling a handler method for each node,
  * appropriate to the type of the node.
@@ -192,8 +190,7 @@ public class RexShuttle implements RexVisitor<RexNode> {
       RexNode clonedOperand = collation.left.accept(this);
       if ((clonedOperand != collation.left) && (update != null)) {
         update[0] = true;
-        collation =
-            new RexFieldCollation(clonedOperand, requireNonNull(collation.right));
+        collation = new RexFieldCollation(clonedOperand, collation.right);
       }
       clonedOperands.add(collation);
     }
diff --git a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
index 301348447e..6909d35c96 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
@@ -666,9 +666,7 @@ public class RexSimplify {
   }
 
   private void simplifyList(List<RexNode> terms, RexUnknownAs unknownAs) {
-    for (int i = 0; i < terms.size(); i++) {
-      terms.set(i, simplify(terms.get(i), unknownAs));
-    }
+    terms.replaceAll(e -> simplify(e, unknownAs));
   }
 
   private void simplifyAndTerms(List<RexNode> terms, RexUnknownAs unknownAs) {
@@ -1435,7 +1433,7 @@ public class RexSimplify {
     // but not interfere with the normal simplification recursion
     List<CaseBranch> branches = new ArrayList<>();
     for (CaseBranch branch : inputBranches) {
-      if ((branches.size() > 0 && !isSafeExpression(branch.cond))
+      if ((!branches.isEmpty() && !isSafeExpression(branch.cond))
           || !isSafeExpression(branch.value)) {
         return null;
       }
@@ -1915,7 +1913,10 @@ public class RexSimplify {
         final Comparison comparison = Comparison.of(call);
         if (comparison != null && comparison.ref.equals(ref)) {
           final C c1 = comparison.literal.getValueAs(clazz);
-          assert c1 != null : "value must not be null in " + comparison.literal;
+          if (c1 == null) {
+            throw new AssertionError("value must not be null in "
+                + comparison.literal);
+          }
           switch (predicate.getKind()) {
           case NOT_EQUALS:
             // We want to intersect result with the range set of everything but
diff --git a/core/src/main/java/org/apache/calcite/rex/RexUtil.java b/core/src/main/java/org/apache/calcite/rex/RexUtil.java
index e0f30f9410..227e6e3701 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexUtil.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexUtil.java
@@ -193,10 +193,8 @@ public class RexUtil {
     if (allowCast) {
       if (node.isA(SqlKind.CAST)) {
         RexCall call = (RexCall) node;
-        if (isNullLiteral(call.operands.get(0), false)) {
-          // node is "CAST(NULL as type)"
-          return true;
-        }
+        // node is "CAST(NULL as type)"
+        return isNullLiteral(call.operands.get(0), false);
       }
     }
     return false;
@@ -250,17 +248,15 @@ public class RexUtil {
    * @return Whether the node is a literal
    */
   public static boolean isLiteral(RexNode node, boolean allowCast) {
-    assert node != null;
+    requireNonNull(node, "node");
     if (node.isA(SqlKind.LITERAL)) {
       return true;
     }
     if (allowCast) {
       if (node.isA(SqlKind.CAST)) {
         RexCall call = (RexCall) node;
-        if (isLiteral(call.operands.get(0), false)) {
-          // node is "CAST(literal as type)"
-          return true;
-        }
+        // node is "CAST(literal as type)"
+        return isLiteral(call.operands.get(0), false);
       }
     }
     return false;
@@ -289,7 +285,7 @@ public class RexUtil {
    * @return Whether the node is a reference or access
    */
   public static boolean isReferenceOrAccess(RexNode node, boolean allowCast) {
-    assert node != null;
+    requireNonNull(node, "node");
     if (node instanceof RexInputRef || node instanceof RexFieldAccess) {
       return true;
     }
@@ -1384,7 +1380,8 @@ public class RexUtil {
   /** Flattens a list of OR nodes. */
   public static ImmutableList<RexNode> flattenOr(
       Iterable<? extends RexNode> nodes) {
-    if (nodes instanceof Collection && ((Collection) nodes).isEmpty()) {
+    if (nodes instanceof Collection
+        && ((Collection<? extends RexNode>) nodes).isEmpty()) {
       // Optimize common case
       return ImmutableList.of();
     }
@@ -1609,7 +1606,7 @@ public class RexUtil {
       SqlOperator op) {
     if (isFlat(exprs, op)) {
       //noinspection unchecked
-      return (List) exprs;
+      return (List<RexNode>) exprs;
     }
     final List<RexNode> list = new ArrayList<>();
     flattenRecurse(list, exprs, op);
@@ -2863,7 +2860,7 @@ public class RexUtil {
   /** Visitor that collects all the top level SubQueries {@link RexSubQuery}
    *  in a projection list of a given {@link Project}.*/
   public static class SubQueryCollector extends RexVisitorImpl<Void> {
-    private List<RexSubQuery> subQueries;
+    private final List<RexSubQuery> subQueries;
     private SubQueryCollector() {
       super(true);
       this.subQueries = new ArrayList<>();
diff --git a/core/src/main/java/org/apache/calcite/rex/RexVariable.java b/core/src/main/java/org/apache/calcite/rex/RexVariable.java
index cf1262bc57..482bf01d60 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexVariable.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexVariable.java
@@ -18,7 +18,7 @@ package org.apache.calcite.rex;
 
 import org.apache.calcite.rel.type.RelDataType;
 
-import java.util.Objects;
+import static java.util.Objects.requireNonNull;
 
 /**
  * A row-expression which references a field.
@@ -34,9 +34,9 @@ public abstract class RexVariable extends RexNode {
   protected RexVariable(
       String name,
       RelDataType type) {
-    this.name = Objects.requireNonNull(name, "name");
-    this.digest = Objects.requireNonNull(name, "name");
-    this.type = Objects.requireNonNull(type, "type");
+    this.name = requireNonNull(name, "name");
+    this.digest = requireNonNull(name, "name");
+    this.type = requireNonNull(type, "type");
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexWindow.java b/core/src/main/java/org/apache/calcite/rex/RexWindow.java
index 6e3ee28ff8..3c39f47064 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexWindow.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexWindow.java
@@ -95,16 +95,6 @@ public class RexWindow {
         "use RANGE for unbounded, not ROWS");
   }
 
-  RexWindow(
-      List<RexNode> partitionKeys,
-      List<RexFieldCollation> orderKeys,
-      RexWindowBound lowerBound,
-      RexWindowBound upperBound,
-      boolean isRows) {
-    this(partitionKeys, orderKeys, lowerBound, upperBound, isRows,
-        RexWindowExclusion.EXCLUDE_NO_OTHER);
-  }
-
   //~ Methods ----------------------------------------------------------------
 
   @Override public String toString() {
@@ -138,7 +128,7 @@ public class RexWindow {
 
   private StringBuilder appendDigest_(StringBuilder sb, boolean allowFraming) {
     final int initialLength = sb.length();
-    if (partitionKeys.size() > 0) {
+    if (!partitionKeys.isEmpty()) {
       sb.append("PARTITION BY ");
       for (int i = 0; i < partitionKeys.size(); i++) {
         if (i > 0) {
@@ -147,7 +137,7 @@ public class RexWindow {
         sb.append(partitionKeys.get(i));
       }
     }
-    if (orderKeys.size() > 0) {
+    if (!orderKeys.isEmpty()) {
       sb.append(sb.length() > initialLength ? " ORDER BY " : "ORDER BY ");
       for (int i = 0; i < orderKeys.size(); i++) {
         if (i > 0) {
diff --git a/core/src/main/java/org/apache/calcite/rex/RexWindowBounds.java b/core/src/main/java/org/apache/calcite/rex/RexWindowBounds.java
index c7af903717..37c209e1ab 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexWindowBounds.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexWindowBounds.java
@@ -26,6 +26,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.Objects;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Helpers for {@link RexWindowBound}.
  */
@@ -62,7 +64,7 @@ public final class RexWindowBounds {
     if (SqlWindow.isCurrentRow(node)) {
       return CURRENT_ROW;
     }
-    assert rexNode != null : "offset value cannot be null for bounded window";
+    requireNonNull(rexNode, "offset value cannot be null for bounded window");
     return new RexBoundedWindowBound((RexCall) rexNode);
   }
 
@@ -136,8 +138,7 @@ public final class RexWindowBounds {
     }
 
     @Override public boolean equals(@Nullable Object o) {
-      return this == o
-          || o instanceof RexCurrentRowWindowBound;
+      return o instanceof RexCurrentRowWindowBound;
     }
 
     @Override public int hashCode() {
@@ -153,13 +154,12 @@ public final class RexWindowBounds {
     private final RexNode offset;
 
     RexBoundedWindowBound(RexCall node) {
-      this.offset = Objects.requireNonNull(node.operands.get(0));
-      this.sqlKind = Objects.requireNonNull(node.getKind());
+      this(node.getKind(), node.operands.get(0));
     }
 
     private RexBoundedWindowBound(SqlKind sqlKind, RexNode offset) {
-      this.sqlKind = sqlKind;
-      this.offset = offset;
+      this.sqlKind = requireNonNull(sqlKind, "sqlKind");
+      this.offset = requireNonNull(offset, "offset");
     }
 
     @Override public boolean isPreceding() {
diff --git a/core/src/main/java/org/apache/calcite/runtime/Automaton.java b/core/src/main/java/org/apache/calcite/runtime/Automaton.java
index bb8f2ca450..86832cfc40 100644
--- a/core/src/main/java/org/apache/calcite/runtime/Automaton.java
+++ b/core/src/main/java/org/apache/calcite/runtime/Automaton.java
@@ -25,6 +25,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.Objects;
 
+import static java.util.Objects.requireNonNull;
+
 /** A nondeterministic finite-state automaton (NFA).
  *
  * <p>It is used to implement the {@link Match}
@@ -46,11 +48,12 @@ public class Automaton {
       ImmutableList<SymbolTransition> transitions,
       ImmutableList<EpsilonTransition> epsilonTransitions,
       ImmutableList<String> symbolNames) {
-    this.startState = Objects.requireNonNull(startState, "startState");
-    this.endState = Objects.requireNonNull(endState, "endState");
-    this.transitions = Objects.requireNonNull(transitions, "transitions");
-    this.epsilonTransitions = epsilonTransitions;
-    this.symbolNames = Objects.requireNonNull(symbolNames, "symbolNames");
+    this.startState = requireNonNull(startState, "startState");
+    this.endState = requireNonNull(endState, "endState");
+    this.transitions = requireNonNull(transitions, "transitions");
+    this.epsilonTransitions =
+        requireNonNull(epsilonTransitions, "epsilonTransitions");
+    this.symbolNames = requireNonNull(symbolNames, "symbolNames");
   }
 
   /** Returns the set of states, represented as a bit set, that the graph is
@@ -122,8 +125,8 @@ public class Automaton {
     final State toState;
 
     Transition(State fromState, State toState) {
-      this.fromState = Objects.requireNonNull(fromState, "fromState");
-      this.toState = Objects.requireNonNull(toState, "toState");
+      this.fromState = requireNonNull(fromState, "fromState");
+      this.toState = requireNonNull(toState, "toState");
     }
   }
 
diff --git a/core/src/main/java/org/apache/calcite/runtime/AutomatonBuilder.java b/core/src/main/java/org/apache/calcite/runtime/AutomatonBuilder.java
index 2785321b05..683d50078c 100644
--- a/core/src/main/java/org/apache/calcite/runtime/AutomatonBuilder.java
+++ b/core/src/main/java/org/apache/calcite/runtime/AutomatonBuilder.java
@@ -28,11 +28,12 @@ import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.collect.ImmutableList.toImmutableList;
 
+import static java.util.Objects.requireNonNull;
+
 /** Builds a state-transition graph for deterministic finite automaton. */
 public class AutomatonBuilder {
   private final Map<String, Integer> symbolIds = new HashMap<>();
@@ -121,7 +122,7 @@ public class AutomatonBuilder {
   /** Adds a symbol transition. */
   AutomatonBuilder symbol(State fromState, State toState,
       String name) {
-    Objects.requireNonNull(name, "name");
+    requireNonNull(name, "name");
     final int symbolId =
         symbolIds.computeIfAbsent(name, k -> symbolIds.size());
     transitionList.add(new SymbolTransition(fromState, toState, symbolId));
diff --git a/core/src/main/java/org/apache/calcite/runtime/BufferStyle.java b/core/src/main/java/org/apache/calcite/runtime/BufferStyle.java
index 314a6bd250..ada4d91a70 100644
--- a/core/src/main/java/org/apache/calcite/runtime/BufferStyle.java
+++ b/core/src/main/java/org/apache/calcite/runtime/BufferStyle.java
@@ -20,6 +20,8 @@ import org.locationtech.jts.operation.buffer.BufferParameters;
 
 import java.util.Locale;
 
+import static java.lang.Integer.parseInt;
+
 /**
  * A parser for buffer styles as defined by PostGIS.
  */
@@ -48,7 +50,7 @@ public class BufferStyle {
       switch (key) {
       case "quad_segs":
         try {
-          quadrantSegments = Integer.parseInt(value);
+          quadrantSegments = parseInt(value);
           break;
         } catch (NumberFormatException e) {
           throw new IllegalArgumentException("Invalid buffer style: " + style);
diff --git a/core/src/main/java/org/apache/calcite/runtime/CalciteContextException.java b/core/src/main/java/org/apache/calcite/runtime/CalciteContextException.java
index eb0ee560ba..3c00f8c633 100644
--- a/core/src/main/java/org/apache/calcite/runtime/CalciteContextException.java
+++ b/core/src/main/java/org/apache/calcite/runtime/CalciteContextException.java
@@ -23,6 +23,8 @@ package org.apache.calcite.runtime;
 import org.checkerframework.checker.initialization.qual.UnknownInitialization;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Exception which contains information about the textual context of the causing
  * exception.
@@ -79,8 +81,7 @@ public class CalciteContextException extends CalciteException {
       int posColumn,
       int endPosLine,
       int endPosColumn) {
-    super(message, cause);
-    assert cause != null;
+    super(message, requireNonNull(cause, "cause"));
     setPosition(posLine, posColumn, endPosLine, endPosColumn);
   }
 
diff --git a/core/src/main/java/org/apache/calcite/runtime/DeterministicAutomaton.java b/core/src/main/java/org/apache/calcite/runtime/DeterministicAutomaton.java
index 69d57c55d2..6bdaefb782 100644
--- a/core/src/main/java/org/apache/calcite/runtime/DeterministicAutomaton.java
+++ b/core/src/main/java/org/apache/calcite/runtime/DeterministicAutomaton.java
@@ -27,6 +27,8 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A deterministic finite automaton (DFA).
  *
@@ -42,7 +44,7 @@ public class DeterministicAutomaton {
   /** Constructs the DFA from an epsilon-NFA. */
   @SuppressWarnings("method.invocation.invalid")
   DeterministicAutomaton(Automaton automaton) {
-    this.automaton = Objects.requireNonNull(automaton, "automaton");
+    this.automaton = requireNonNull(automaton, "automaton");
     // Calculate eps closure of start state
     final Set<MultiState> traversedStates = new HashSet<>();
     // Add transitions
@@ -146,10 +148,10 @@ public class DeterministicAutomaton {
 
     Transition(MultiState fromState, MultiState toState, int symbolId,
         String symbol) {
-      this.fromState = Objects.requireNonNull(fromState, "fromState");
-      this.toState = Objects.requireNonNull(toState, "toState");
+      this.fromState = requireNonNull(fromState, "fromState");
+      this.toState = requireNonNull(toState, "toState");
       this.symbolId = symbolId;
-      this.symbol = Objects.requireNonNull(symbol, "symbol");
+      this.symbol = requireNonNull(symbol, "symbol");
     }
   }
 
@@ -165,7 +167,7 @@ public class DeterministicAutomaton {
     }
 
     MultiState(ImmutableSet<Automaton.State> states) {
-      this.states = Objects.requireNonNull(states, "states");
+      this.states = requireNonNull(states, "states");
     }
 
     public boolean contains(Automaton.State state) {
diff --git a/core/src/main/java/org/apache/calcite/runtime/Enumerables.java b/core/src/main/java/org/apache/calcite/runtime/Enumerables.java
index 07ede2a510..1f2c537ce1 100644
--- a/core/src/main/java/org/apache/calcite/runtime/Enumerables.java
+++ b/core/src/main/java/org/apache/calcite/runtime/Enumerables.java
@@ -29,11 +29,12 @@ import java.util.Deque;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Consumer;
 import java.util.function.Supplier;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Utilities for processing {@link org.apache.calcite.linq4j.Enumerable}
  * collections.
@@ -96,7 +97,7 @@ public class Enumerables {
           final AtomicInteger matchCounter = new AtomicInteger(1);
 
           @Override public TResult current() {
-            Objects.requireNonNull(resultRow, "resultRow");
+            requireNonNull(resultRow, "resultRow");
             return resultRow;
           }
 
diff --git a/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java b/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java
index 23c4130de3..fb524bb7e0 100644
--- a/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java
+++ b/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java
@@ -16,6 +16,8 @@
  */
 package org.apache.calcite.runtime;
 
+import org.checkerframework.checker.nullness.qual.Nullable;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStreamWriter;
@@ -88,7 +90,7 @@ public class HttpUtils {
 
   public static InputStream post(
       String url,
-      CharSequence data,
+      @Nullable CharSequence data,
       Map<String, String> headers,
       int cTimeout,
       int rTimeout) throws IOException {
@@ -98,7 +100,7 @@ public class HttpUtils {
 
   public static InputStream executeMethod(
       String method, String url,
-      CharSequence data, Map<String, String> headers,
+      @Nullable CharSequence data, @Nullable Map<String, String> headers,
       int cTimeout, int rTimeout) throws IOException {
     // NOTE: do not log "data" or "url"; may contain user name or password.
     final HttpURLConnection conn = getURLConnection(url);
diff --git a/core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java b/core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java
index b613ad1d98..f5ce8dc479 100644
--- a/core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java
@@ -141,7 +141,8 @@ public class JsonFunctions {
       switch (mode) {
       case STRICT:
         if (input.hasException()) {
-          return JsonPathContext.withStrictException(pathSpec, input.exc);
+          return JsonPathContext.withStrictException(pathSpec,
+              requireNonNull(input.exc));
         }
         ctx =
             JsonPath.parse(input.obj(),
@@ -225,7 +226,7 @@ public class JsonFunctions {
         case FALSE:
           return Boolean.FALSE;
         case ERROR:
-          throw toUnchecked(context.exc);
+          throw toUnchecked(requireNonNull(context.exc));
         case UNKNOWN:
           return null;
         default:
@@ -299,7 +300,7 @@ public class JsonFunctions {
       }
       switch (errorBehavior) {
       case ERROR:
-        throw toUnchecked(exc);
+        throw toUnchecked(requireNonNull(exc, "exc"));
       case NULL:
         return null;
       case DEFAULT:
@@ -399,7 +400,7 @@ public class JsonFunctions {
       }
       switch (errorBehavior) {
       case ERROR:
-        throw toUnchecked(exc);
+        throw toUnchecked(requireNonNull(exc, "exc"));
       case NULL:
         return null;
       case EMPTY_ARRAY:
@@ -571,13 +572,9 @@ public class JsonFunctions {
       for (int i = 0; i < size; ++i) {
         Object obj = q.poll();
         if (obj instanceof Map) {
-          for (Object value : ((LinkedHashMap) obj).values()) {
-            q.add(value);
-          }
+          q.addAll(((LinkedHashMap) obj).values());
         } else if (obj instanceof Collection) {
-          for (Object value : (Collection) obj) {
-            q.add(value);
-          }
+          q.addAll((Collection) obj);
         }
       }
       ++depth;
@@ -606,7 +603,7 @@ public class JsonFunctions {
     final Object value;
     try {
       if (context.hasException()) {
-        throw toUnchecked(context.exc);
+        throw toUnchecked(requireNonNull(context.exc));
       }
       value = context.obj;
 
@@ -651,7 +648,7 @@ public class JsonFunctions {
     final Object value;
     try {
       if (context.hasException()) {
-        throw toUnchecked(context.exc);
+        throw toUnchecked(requireNonNull(context.exc));
       }
       value = context.obj;
 
diff --git a/core/src/main/java/org/apache/calcite/runtime/Matcher.java b/core/src/main/java/org/apache/calcite/runtime/Matcher.java
index 64668165e5..b0fdb17ffb 100644
--- a/core/src/main/java/org/apache/calcite/runtime/Matcher.java
+++ b/core/src/main/java/org/apache/calcite/runtime/Matcher.java
@@ -38,6 +38,8 @@ import java.util.function.Consumer;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Workspace that partialMatches patterns against an automaton.
  *
@@ -51,20 +53,17 @@ public class Matcher<E> {
   // but only one thread can use them at a time. Putting them here saves the
   // expense of creating a fresh object each call to "match".
 
-  @SuppressWarnings("unused")
-  private final ImmutableBitSet startSet;
-
   /**
    * Creates a Matcher; use {@link #builder}.
    */
   private Matcher(Automaton automaton,
       ImmutableMap<String, Predicate<MemoryFactory.Memory<E>>> predicates) {
-    this.predicates = Objects.requireNonNull(predicates, "predicates");
+    this.predicates = requireNonNull(predicates, "predicates");
     final ImmutableBitSet.Builder startSetBuilder =
         ImmutableBitSet.builder();
     startSetBuilder.set(automaton.startState.id);
     automaton.epsilonSuccessors(automaton.startState.id, startSetBuilder);
-    startSet = startSetBuilder.build();
+    ImmutableBitSet unusedStartSet = startSetBuilder.build();
     // Build the DFA
     dfa = new DeterministicAutomaton(automaton);
   }
diff --git a/core/src/main/java/org/apache/calcite/runtime/Pattern.java b/core/src/main/java/org/apache/calcite/runtime/Pattern.java
index 370eb02d6d..6fb331d80c 100644
--- a/core/src/main/java/org/apache/calcite/runtime/Pattern.java
+++ b/core/src/main/java/org/apache/calcite/runtime/Pattern.java
@@ -18,12 +18,13 @@ package org.apache.calcite.runtime;
 
 import com.google.common.collect.ImmutableList;
 
-import java.util.Objects;
 import java.util.Stack;
 import java.util.stream.Collectors;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /** Regular expression, to be compiled into an {@link Automaton}. */
 public interface Pattern {
   default Automaton toAutomaton() {
@@ -153,7 +154,7 @@ public interface Pattern {
     final Op op;
 
     AbstractPattern(Op op) {
-      this.op = Objects.requireNonNull(op, "op");
+      this.op = requireNonNull(op, "op");
     }
 
     @Override public Automaton toAutomaton() {
@@ -167,7 +168,7 @@ public interface Pattern {
 
     SymbolPattern(String name) {
       super(Op.SYMBOL);
-      this.name = Objects.requireNonNull(name, "name");
+      this.name = requireNonNull(name, "name");
     }
 
     @Override public String toString() {
diff --git a/core/src/main/java/org/apache/calcite/runtime/Resources.java b/core/src/main/java/org/apache/calcite/runtime/Resources.java
index a015541a38..b0ec8c9922 100644
--- a/core/src/main/java/org/apache/calcite/runtime/Resources.java
+++ b/core/src/main/java/org/apache/calcite/runtime/Resources.java
@@ -54,7 +54,9 @@ import java.util.ResourceBundle;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 
-import static java.lang.reflect.Modifier.isStatic;
+import static java.lang.Boolean.parseBoolean;
+
+import static java.lang.Double.parseDouble;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 
@@ -245,7 +247,9 @@ public class Resources {
         }
         try {
           Inst inst = (Inst) method.invoke(o, args);
-          assert inst != null : "got null from " + method;
+          if (inst == null) {
+            throw new AssertionError("got null from " + method);
+          }
           inst.validate(validations);
         } catch (IllegalAccessException e) {
           throw new RuntimeException("in " + method, e);
@@ -694,7 +698,7 @@ public class Resources {
       super(accessor, method);
       final Default resource = getDefault();
       if (resource != null) {
-        defaultValue = Boolean.parseBoolean(resource.value());
+        defaultValue = parseBoolean(resource.value());
       } else {
         defaultValue = false;
       }
@@ -725,7 +729,7 @@ public class Resources {
       super(accessor, method);
       final Default resource = getDefault();
       if (resource != null) {
-        defaultValue = Double.parseDouble(resource.value());
+        defaultValue = parseDouble(resource.value());
       } else {
         defaultValue = 0d;
       }
@@ -1149,7 +1153,7 @@ public class Resources {
     public boolean booleanValue(BooleanProp p) {
       final String s = properties.getProperty(p.key);
       if (s != null) {
-        return Boolean.parseBoolean(s);
+        return parseBoolean(s);
       }
       p.checkDefault2();
       return p.defaultValue;
@@ -1158,14 +1162,14 @@ public class Resources {
     @Override
     public boolean booleanValue(BooleanProp p, boolean defaultValue) {
       final String s = properties.getProperty(p.key);
-      return s == null ? defaultValue : Boolean.parseBoolean(s);
+      return s == null ? defaultValue : parseBoolean(s);
     }
 
     @Override
     public double doubleValue(DoubleProp p) {
       final String s = properties.getProperty(p.key);
       if (s != null) {
-        return Double.parseDouble(s);
+        return parseDouble(s);
       }
       p.checkDefault2();
       return p.defaultValue;
@@ -1174,7 +1178,7 @@ public class Resources {
     @Override
     public double doubleValue(DoubleProp p, double defaultValue) {
       final String s = properties.getProperty(p.key);
-      return s == null ? defaultValue : Double.parseDouble(s);
+      return s == null ? defaultValue : parseDouble(s);
     }
   }
 }
diff --git a/core/src/main/java/org/apache/calcite/runtime/SocketFactoryImpl.java b/core/src/main/java/org/apache/calcite/runtime/SocketFactoryImpl.java
index 857fd98630..8504531103 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SocketFactoryImpl.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SocketFactoryImpl.java
@@ -93,7 +93,7 @@ public class SocketFactoryImpl extends SocketFactory {
    */
   public static final int LINGER = 0;
 
-  @Override public Socket createSocket() throws IOException {
+  @Override public Socket createSocket() {
     Socket s = new Socket();
     return applySettings(s);
   }
diff --git a/core/src/main/java/org/apache/calcite/runtime/SpatialTypeFunctions.java b/core/src/main/java/org/apache/calcite/runtime/SpatialTypeFunctions.java
index 5587711d91..1942ef22d9 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SpatialTypeFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SpatialTypeFunctions.java
@@ -74,7 +74,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Objects;
 import java.util.function.Function;
 import java.util.stream.Stream;
 
@@ -92,6 +91,8 @@ import static org.apache.calcite.runtime.SpatialTypeUtils.fromWkb;
 import static org.apache.calcite.runtime.SpatialTypeUtils.fromWkt;
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Helper methods to implement spatial type (ST) functions in generated code.
  *
@@ -597,7 +598,7 @@ public class SpatialTypeFunctions {
         + xMax + " " + yMax + ", "
         + xMax + " " + yMin + ", "
         + xMin + " " + yMin + "))", srid);
-    return Objects.requireNonNull(geom, "geom");
+    return requireNonNull(geom, "geom");
   }
 
   /**
@@ -1800,7 +1801,6 @@ public class SpatialTypeFunctions {
    * Used at run time by the {@link #ST_MakeGrid} and {@link #ST_MakeGridPoints} functions.
    */
   public static class GridEnumerable extends AbstractEnumerable<Object[]> {
-    private final Envelope envelope;
     private final boolean point;
     private final double deltaX;
     private final double deltaY;
@@ -1814,7 +1814,6 @@ public class SpatialTypeFunctions {
 
     public GridEnumerable(Envelope envelope, BigDecimal deltaX,
         BigDecimal deltaY, boolean point) {
-      this.envelope = envelope;
       this.deltaX = deltaX.doubleValue();
       this.deltaY = deltaY.doubleValue();
       this.point = point;
diff --git a/core/src/main/java/org/apache/calcite/runtime/SpatialTypeUtils.java b/core/src/main/java/org/apache/calcite/runtime/SpatialTypeUtils.java
index 49320220c5..f23514370e 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SpatialTypeUtils.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SpatialTypeUtils.java
@@ -40,6 +40,8 @@ import java.util.Locale;
 import java.util.regex.Pattern;
 import javax.xml.parsers.ParserConfigurationException;
 
+import static java.lang.Integer.parseInt;
+
 /**
  * Utilities for spatial types.
  */
@@ -177,7 +179,7 @@ public class SpatialTypeUtils {
     Geometry geometry = fromWkt(wkt);
     String srid = matcher.group(1);
     if (srid != null) {
-      geometry.setSRID(Integer.parseInt(srid));
+      geometry.setSRID(parseInt(srid));
     }
 
     return geometry;
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index 7da9705c1c..b23fc6ede0 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -134,6 +134,12 @@ import static org.apache.calcite.config.CalciteSystemProperty.FUNCTION_LEVEL_CAC
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.lang.Byte.parseByte;
+import static java.lang.Double.parseDouble;
+import static java.lang.Float.parseFloat;
+import static java.lang.Integer.parseInt;
+import static java.lang.Long.parseLong;
+import static java.lang.Short.parseShort;
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static java.util.Objects.requireNonNull;
 import static java.util.stream.Collectors.joining;
@@ -969,9 +975,9 @@ public class SqlFunctions {
   * operator. */
   public static boolean containsSubstr(String jsonString, String substr,
       String jsonScope) {
-    LinkedHashMap<String, String> map =
-        (LinkedHashMap<String, String>) JsonFunctions.dejsonize(jsonString);
-    assert map != null;
+    final Object o = requireNonNull(JsonFunctions.dejsonize(jsonString));
+    @SuppressWarnings("unchecked") LinkedHashMap<String, String> map =
+        (LinkedHashMap<String, String>) o;
     Set<String> keys = map.keySet();
     Collection<String> values = map.values();
     try {
@@ -1441,7 +1447,7 @@ public class SqlFunctions {
    * SQL TO_CODE_POINTS(string) function.
    */
   public static @Nullable List<Integer> toCodePoints(String s) {
-    if (s.length() == 0) {
+    if (s.isEmpty()) {
       return null;
     }
     final ImmutableList.Builder<Integer> builder = new ImmutableList.Builder<>();
@@ -3823,7 +3829,7 @@ public class SqlFunctions {
   public static byte toByte(Object o) {
     return o instanceof Byte ? (Byte) o
         : o instanceof Number ? toByte((Number) o)
-        : Byte.parseByte(o.toString());
+        : parseByte(o.toString());
   }
 
   public static byte toByte(Number number) {
@@ -3839,7 +3845,7 @@ public class SqlFunctions {
   }
 
   public static short toShort(String s) {
-    return Short.parseShort(s.trim());
+    return parseShort(s.trim());
   }
 
   public static short toShort(Number number) {
@@ -3948,7 +3954,7 @@ public class SqlFunctions {
   }
 
   public static int toInt(String s) {
-    return Integer.parseInt(s.trim());
+    return parseInt(s.trim());
   }
 
   public static int toInt(Number number) {
@@ -4052,7 +4058,7 @@ public class SqlFunctions {
     if (s.startsWith("199") && s.contains(":")) {
       return Timestamp.valueOf(s).getTime();
     }
-    return Long.parseLong(s.trim());
+    return parseLong(s.trim());
   }
 
   public static long toLong(Number number) {
@@ -4075,7 +4081,7 @@ public class SqlFunctions {
   }
 
   public static float toFloat(String s) {
-    return Float.parseFloat(s.trim());
+    return parseFloat(s.trim());
   }
 
   public static float toFloat(Number number) {
@@ -4090,7 +4096,7 @@ public class SqlFunctions {
   }
 
   public static double toDouble(String s) {
-    return Double.parseDouble(s.trim());
+    return parseDouble(s.trim());
   }
 
   public static double toDouble(Number number) {
@@ -4212,7 +4218,7 @@ public class SqlFunctions {
   public static long timeWithLocalTimeZoneToTimestamp(String date, int v, TimeZone timeZone) {
     final TimeWithTimeZoneString tTZ = TimeWithTimeZoneString.fromMillisOfDay(v)
         .withTimeZone(DateTimeUtils.UTC_ZONE);
-    return new TimestampWithTimeZoneString(date + " " + tTZ.toString())
+    return new TimestampWithTimeZoneString(date + " " + tTZ)
         .withTimeZone(timeZone)
         .getLocalTimestampString()
         .getMillisSinceEpoch();
@@ -4221,7 +4227,7 @@ public class SqlFunctions {
   public static long timeWithLocalTimeZoneToTimestampWithLocalTimeZone(String date, int v) {
     final TimeWithTimeZoneString tTZ = TimeWithTimeZoneString.fromMillisOfDay(v)
         .withTimeZone(DateTimeUtils.UTC_ZONE);
-    return new TimestampWithTimeZoneString(date + " " + tTZ.toString())
+    return new TimestampWithTimeZoneString(date + " " + tTZ)
         .getLocalTimestampString()
         .getMillisSinceEpoch();
   }
@@ -5520,7 +5526,7 @@ public class SqlFunctions {
     final List smaller = list1;
     final List bigger = list2;
     boolean hasNull = false;
-    if (smaller.size() > 0 && bigger.size() > 0) {
+    if (!smaller.isEmpty() && !bigger.isEmpty()) {
       final Set smallestSet = new HashSet(smaller);
       hasNull = smallestSet.remove(null);
       for (Object element : bigger) {
@@ -5630,7 +5636,7 @@ public class SqlFunctions {
   public static Long arrayPosition(List list, Object element) {
     final int index = list.indexOf(element);
     if (index != -1) {
-      return Long.valueOf(index + 1L);
+      return index + 1L;
     }
     return 0L;
   }
diff --git a/core/src/main/java/org/apache/calcite/schema/impl/ModifiableViewTable.java b/core/src/main/java/org/apache/calcite/schema/impl/ModifiableViewTable.java
index 99f81d4d26..aee998c0eb 100644
--- a/core/src/main/java/org/apache/calcite/schema/impl/ModifiableViewTable.java
+++ b/core/src/main/java/org/apache/calcite/schema/impl/ModifiableViewTable.java
@@ -115,8 +115,8 @@ public class ModifiableViewTable extends ViewTable
    */
   public final ModifiableViewTable extend(
       List<RelDataTypeField> extendedColumns, RelDataTypeFactory typeFactory) {
-    final ExtensibleTable underlying = unwrap(ExtensibleTable.class);
-    assert underlying != null;
+    final ExtensibleTable underlying =
+        requireNonNull(unwrap(ExtensibleTable.class));
 
     final RelDataTypeFactory.Builder builder = typeFactory.builder();
     final RelDataType rowType = getRowType(typeFactory);
diff --git a/core/src/main/java/org/apache/calcite/schema/impl/StarTable.java b/core/src/main/java/org/apache/calcite/schema/impl/StarTable.java
index 97a17ec0db..e8dad3b662 100644
--- a/core/src/main/java/org/apache/calcite/schema/impl/StarTable.java
+++ b/core/src/main/java/org/apache/calcite/schema/impl/StarTable.java
@@ -41,10 +41,11 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Virtual table that is composed of two or more tables joined together.
  *
@@ -68,7 +69,7 @@ public class StarTable extends AbstractTable implements TranslatableTable {
 
   /** Creates a StarTable. */
   private StarTable(Lattice lattice, ImmutableList<Table> tables) {
-    this.lattice = Objects.requireNonNull(lattice, "lattice");
+    this.lattice = requireNonNull(lattice, "lattice");
     this.tables = tables;
   }
 
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlAccessType.java b/core/src/main/java/org/apache/calcite/sql/SqlAccessType.java
index d33a7e5557..c07e58293c 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlAccessType.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlAccessType.java
@@ -19,6 +19,8 @@ package org.apache.calcite.sql;
 import java.util.EnumSet;
 import java.util.Locale;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * SqlAccessType is represented by a set of allowed access types.
  *
@@ -55,9 +57,8 @@ public class SqlAccessType {
   }
 
   public static SqlAccessType create(String[] accessNames) {
-    assert accessNames != null;
     EnumSet<SqlAccessEnum> enumSet = EnumSet.noneOf(SqlAccessEnum.class);
-    for (String accessName : accessNames) {
+    for (String accessName : requireNonNull(accessNames, "accessNames")) {
       enumSet.add(
           SqlAccessEnum.valueOf(accessName.trim().toUpperCase(Locale.ROOT)));
     }
@@ -65,10 +66,10 @@ public class SqlAccessType {
   }
 
   public static SqlAccessType create(String accessString) {
-    assert accessString != null;
-    accessString = accessString.replace('[', ' ');
-    accessString = accessString.replace(']', ' ');
-    String[] accessNames = accessString.split(",");
-    return create(accessNames);
+    return create(
+        requireNonNull(accessString, "accessString")
+            .replace('[', ' ')
+            .replace(']', ' ')
+            .split(","));
   }
 }
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlAggFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlAggFunction.java
index 208b34bd83..b7f7df233e 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlAggFunction.java
@@ -31,7 +31,8 @@ import org.apache.calcite.util.Optionality;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Abstract base class for the definition of an aggregate function: an operator
@@ -111,7 +112,8 @@ public abstract class SqlAggFunction extends SqlFunction implements Context {
         operandTypeChecker, funcType);
     this.requiresOrder = requiresOrder;
     this.requiresOver = requiresOver;
-    this.requiresGroupOrder = Objects.requireNonNull(requiresGroupOrder, "requiresGroupOrder");
+    this.requiresGroupOrder =
+        requireNonNull(requiresGroupOrder, "requiresGroupOrder");
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlBasicCall.java b/core/src/main/java/org/apache/calcite/sql/SqlBasicCall.java
index a3bb12007d..8279924af1 100755
--- a/core/src/main/java/org/apache/calcite/sql/SqlBasicCall.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlBasicCall.java
@@ -22,10 +22,11 @@ import org.apache.calcite.util.ImmutableNullableList;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Implementation of {@link SqlCall} that keeps its operands in an array.
  */
@@ -73,7 +74,7 @@ public class SqlBasicCall extends SqlCall {
       SqlParserPos pos,
       @Nullable SqlLiteral functionQualifier) {
     super(pos);
-    this.operator = Objects.requireNonNull(operator, "operator");
+    this.operator = requireNonNull(operator, "operator");
     this.operandList = ImmutableNullableList.copyOf(operandList);
     this.functionQuantifier = functionQualifier;
   }
@@ -102,7 +103,7 @@ public class SqlBasicCall extends SqlCall {
    * the same operator (for instance, a version where overloading has been
    * resolved); use with care. */
   public void setOperator(SqlOperator operator) {
-    this.operator = Objects.requireNonNull(operator, "operator");
+    this.operator = requireNonNull(operator, "operator");
   }
 
   @Override public SqlOperator getOperator() {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlBasicTypeNameSpec.java b/core/src/main/java/org/apache/calcite/sql/SqlBasicTypeNameSpec.java
index 9b0434d91f..08f4de6ffd 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlBasicTypeNameSpec.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlBasicTypeNameSpec.java
@@ -29,6 +29,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 import java.nio.charset.Charset;
 import java.util.Objects;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A sql type name specification of basic sql type.
  *
@@ -74,10 +76,10 @@ public class SqlBasicTypeNameSpec extends SqlTypeNameSpec {
 
   private final SqlTypeName sqlTypeName;
 
-  private int precision;
-  private int scale;
+  private final int precision;
+  private final int scale;
 
-  private @Nullable String charSetName;
+  private final @Nullable String charSetName;
 
   /**
    * Create a basic sql type name specification.
@@ -221,14 +223,12 @@ public class SqlBasicTypeNameSpec extends SqlTypeNameSpec {
         charset = typeFactory.getDefaultCharset();
       } else {
         String javaCharSetName =
-            Objects.requireNonNull(
+            requireNonNull(
                 SqlUtil.translateCharacterSetName(charSetName), charSetName);
         charset = Charset.forName(javaCharSetName);
       }
       type =
-          typeFactory.createTypeWithCharsetAndCollation(
-              type,
-              charset,
+          typeFactory.createTypeWithCharsetAndCollation(type, charset,
               collation);
     }
     return type;
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlBinaryStringLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlBinaryStringLiteral.java
index 9dd3d66906..720cacb6af 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlBinaryStringLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlBinaryStringLiteral.java
@@ -22,7 +22,8 @@ import org.apache.calcite.util.BitString;
 import org.apache.calcite.util.Util;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * A binary (or hexadecimal) string literal.
@@ -52,7 +53,7 @@ public class SqlBinaryStringLiteral extends SqlAbstractStringLiteral {
   }
 
   private BitString getValueNonNull() {
-    return (BitString) Objects.requireNonNull(value, "value");
+    return (BitString) requireNonNull(value, "value");
   }
 
   @Override public SqlBinaryStringLiteral clone(SqlParserPos pos) {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCall.java b/core/src/main/java/org/apache/calcite/sql/SqlCall.java
index 7a69938815..f77aab9d7b 100755
--- a/core/src/main/java/org/apache/calcite/sql/SqlCall.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlCall.java
@@ -32,10 +32,11 @@ import org.checkerframework.dataflow.qual.Pure;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
-import java.util.Objects;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A <code>SqlCall</code> is a call to an {@link SqlOperator operator}.
  * (Operators can be used to describe any syntactic construct, so in practice,
@@ -198,8 +199,7 @@ public abstract class SqlCall extends SqlNode {
     List<String> signatureList = new ArrayList<>();
     for (final SqlNode operand : getOperandList()) {
       final RelDataType argType =
-          validator.deriveType(Objects.requireNonNull(scope, "scope"),
-              operand);
+          validator.deriveType(requireNonNull(scope, "scope"), operand);
       if (null == argType) {
         continue;
       }
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCharStringLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlCharStringLiteral.java
index 46fbc332d7..2f720f774b 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlCharStringLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlCharStringLiteral.java
@@ -25,7 +25,8 @@ import org.apache.calcite.util.Util;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * A character string literal.
@@ -54,7 +55,7 @@ public class SqlCharStringLiteral extends SqlAbstractStringLiteral {
   }
 
   private NlsString getValueNonNull() {
-    return (NlsString) Objects.requireNonNull(value, "value");
+    return (NlsString) requireNonNull(value, "value");
   }
   /**
    * Returns the collation.
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCollectionTypeNameSpec.java b/core/src/main/java/org/apache/calcite/sql/SqlCollectionTypeNameSpec.java
index bda8d8ec71..ed996cc321 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlCollectionTypeNameSpec.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlCollectionTypeNameSpec.java
@@ -26,6 +26,8 @@ import org.apache.calcite.util.Util;
 
 import java.util.Objects;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A sql type name specification of collection type.
  *
@@ -69,8 +71,9 @@ public class SqlCollectionTypeNameSpec extends SqlTypeNameSpec {
       SqlTypeName collectionTypeName,
       SqlParserPos pos) {
     super(new SqlIdentifier(collectionTypeName.name(), pos), pos);
-    this.elementTypeName = Objects.requireNonNull(elementTypeName, "elementTypeName");
-    this.collectionTypeName = Objects.requireNonNull(collectionTypeName, "collectionTypeName");
+    this.elementTypeName = requireNonNull(elementTypeName, "elementTypeName");
+    this.collectionTypeName =
+        requireNonNull(collectionTypeName, "collectionTypeName");
   }
 
   public SqlTypeNameSpec getElementTypeName() {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDateLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlDateLiteral.java
index d90a895c1b..961e8af1ac 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlDateLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlDateLiteral.java
@@ -22,7 +22,7 @@ import org.apache.calcite.sql.parser.SqlParserPos;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.DateString;
 
-import java.util.Objects;
+import static java.util.Objects.requireNonNull;
 
 /**
  * A SQL literal representing a DATE value, such as <code>DATE
@@ -41,7 +41,7 @@ public class SqlDateLiteral extends SqlAbstractDateTimeLiteral {
 
   /** Converts this literal to a {@link DateString}. */
   protected DateString getDate() {
-    return (DateString) Objects.requireNonNull(value, "value");
+    return (DateString) requireNonNull(value, "value");
   }
 
   @Override public SqlDateLiteral clone(SqlParserPos pos) {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDdl.java b/core/src/main/java/org/apache/calcite/sql/SqlDdl.java
index 5480fb7571..923118e93d 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlDdl.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlDdl.java
@@ -18,7 +18,7 @@ package org.apache.calcite.sql;
 
 import org.apache.calcite.sql.parser.SqlParserPos;
 
-import java.util.Objects;
+import static java.util.Objects.requireNonNull;
 
 /** Base class for CREATE, DROP and other DDL statements. */
 public abstract class SqlDdl extends SqlCall {
@@ -31,7 +31,7 @@ public abstract class SqlDdl extends SqlCall {
   /** Creates a SqlDdl. */
   protected SqlDdl(SqlOperator operator, SqlParserPos pos) {
     super(pos);
-    this.operator = Objects.requireNonNull(operator, "operator");
+    this.operator = requireNonNull(operator, "operator");
   }
 
   @Override public SqlOperator getOperator() {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java b/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java
index 4a61e53ea2..b956bebc00 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java
@@ -22,7 +22,8 @@ import org.apache.calcite.util.ImmutableNullableList;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * A <code>SqlDescribeTable</code> is a node of a parse tree that represents a
@@ -48,7 +49,7 @@ public class SqlDescribeTable extends SqlCall {
       SqlIdentifier table,
       @Nullable SqlIdentifier column) {
     super(pos);
-    this.table = Objects.requireNonNull(table, "table");
+    this.table = requireNonNull(table, "table");
     this.column = column;
   }
 
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlFilterOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlFilterOperator.java
index 03ecb00606..4160fb6d69 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlFilterOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlFilterOperator.java
@@ -25,10 +25,10 @@ import org.apache.calcite.sql.validate.SqlValidatorImpl;
 import org.apache.calcite.sql.validate.SqlValidatorScope;
 import org.apache.calcite.sql.validate.SqlValidatorUtil;
 
-import java.util.Objects;
-
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * An operator that applies a filter before rows are included in an aggregate
  * function.
@@ -81,7 +81,7 @@ public class SqlFilterOperator extends SqlBinaryOperator {
     validator.validateAggregateParams(aggCall, flat.filter,
         flat.distinctList, flat.orderList, scope);
 
-    final SqlNode filter = Objects.requireNonNull(flat.filter);
+    final SqlNode filter = requireNonNull(flat.filter);
     final RelDataType type = validator.deriveType(scope, filter);
     if (!SqlTypeUtil.inBooleanFamily(type)) {
       throw validator.newValidationError(filter,
@@ -117,11 +117,11 @@ public class SqlFilterOperator extends SqlBinaryOperator {
     validator1.setValidatedNodeType(aggCall, ret);
     if (flat.distinctList != null) {
       validator1.setValidatedNodeType(
-          Objects.requireNonNull(flat.distinctCall), ret);
+          requireNonNull(flat.distinctCall), ret);
     }
     if (flat.orderList != null) {
       validator1.setValidatedNodeType(
-          Objects.requireNonNull(flat.orderCall), ret);
+          requireNonNull(flat.orderCall), ret);
     }
     return ret;
   }
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlFunction.java
index 57e4748563..156150c419 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlFunction.java
@@ -34,11 +34,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 import org.checkerframework.dataflow.qual.Pure;
 
 import java.util.List;
-import java.util.Objects;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A <code>SqlFunction</code> is a type of operator which has conventional
  * function-call syntax.
@@ -132,7 +133,7 @@ public class SqlFunction extends SqlOperator {
         operandTypeChecker);
 
     this.sqlIdentifier = sqlIdentifier;
-    this.category = Objects.requireNonNull(category, "category");
+    this.category = requireNonNull(category, "category");
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlHint.java b/core/src/main/java/org/apache/calcite/sql/SqlHint.java
index acb41eb6d7..7c26e7fda0 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlHint.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlHint.java
@@ -161,8 +161,9 @@ public class SqlHint extends SqlCall {
 
   @Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
     name.unparse(writer, leftPrec, rightPrec);
-    if (this.options.size() > 0) {
-      SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")");
+    if (!this.options.isEmpty()) {
+      SqlWriter.Frame frame =
+          writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")");
       for (int i = 0; i < options.size(); i++) {
         SqlNode option = options.get(i);
         SqlNode nextOption = i < options.size() - 1 ? options.get(i + 1) : null;
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java b/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java
index 6742057bfb..e3214579d3 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java
@@ -89,9 +89,6 @@ public class SqlIdentifier extends SqlNode {
     this.componentPositions =
         componentPositions == null ? null
             : ImmutableList.copyOf(componentPositions);
-    for (String name : names) {
-      assert name != null;
-    }
   }
 
   public SqlIdentifier(List<String> names, SqlParserPos pos) {
@@ -378,7 +375,8 @@ public class SqlIdentifier extends SqlNode {
 
   @Override public SqlMonotonicity getMonotonicity(SqlValidatorScope scope) {
     // for "star" column, whether it's static or dynamic return not_monotonic directly.
-    if (Util.last(names).equals("") || DynamicRecordType.isDynamicStarColName(Util.last(names))) {
+    if (Util.last(names).isEmpty()
+        || DynamicRecordType.isDynamicStarColName(Util.last(names))) {
       return SqlMonotonicity.NOT_MONOTONIC;
     }
 
@@ -390,7 +388,10 @@ public class SqlIdentifier extends SqlNode {
       return call.getMonotonicity(scope);
     }
     final SqlQualified qualified = scope.fullyQualify(this);
-    assert qualified.namespace != null : "namespace must not be null in " + qualified;
+    if (qualified.namespace == null) {
+      throw new IllegalArgumentException("namespace must not be null in "
+          + qualified);
+    }
     final SqlIdentifier fqId = qualified.identifier;
     return qualified.namespace.resolve().getMonotonicity(Util.last(fqId.names));
   }
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlInsert.java b/core/src/main/java/org/apache/calcite/sql/SqlInsert.java
index f95932bfbf..f0d3ba3e55 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlInsert.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlInsert.java
@@ -26,6 +26,8 @@ import org.checkerframework.dataflow.qual.Pure;
 
 import java.util.List;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A <code>SqlInsert</code> is a node of a parse tree which represents an INSERT
  * statement.
@@ -59,11 +61,10 @@ public class SqlInsert extends SqlCall {
       SqlNode source,
       @Nullable SqlNodeList columnList) {
     super(pos);
-    this.keywords = keywords;
+    this.keywords = requireNonNull(keywords, "keywords");
     this.targetTable = targetTable;
     this.source = source;
     this.columnList = columnList;
-    assert keywords != null;
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlIntervalLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlIntervalLiteral.java
index c9a2d335d7..0f311ce513 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlIntervalLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlIntervalLiteral.java
@@ -24,8 +24,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.Objects;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A SQL literal representing a time interval.
  *
@@ -101,16 +105,13 @@ public class SqlIntervalLiteral extends SqlLiteral {
      * @param sign              Sign (+1 or -1)
      * @param intervalStr       Interval string
      */
-    IntervalValue(
-        SqlIntervalQualifier intervalQualifier,
-        int sign,
+    IntervalValue(SqlIntervalQualifier intervalQualifier, int sign,
         String intervalStr) {
-      assert (sign == -1) || (sign == 1);
-      assert intervalQualifier != null;
-      assert intervalStr != null;
-      this.intervalQualifier = intervalQualifier;
+      this.intervalQualifier =
+          requireNonNull(intervalQualifier, "intervalQualifier");
       this.sign = sign;
-      this.intervalStr = intervalStr;
+      this.intervalStr = requireNonNull(intervalStr, "intervalStr");
+      checkArgument(sign == -1 || sign == 1);
     }
 
     @Override public boolean equals(@Nullable Object obj) {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlIntervalQualifier.java b/core/src/main/java/org/apache/calcite/sql/SqlIntervalQualifier.java
index 638f636601..ccc1072308 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlIntervalQualifier.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlIntervalQualifier.java
@@ -554,8 +554,7 @@ public class SqlIntervalQualifier extends SqlNode {
 
     // YEAR and DAY can never be secondary units,
     // nor can unit be null.
-    assert unit != null;
-    switch (unit) {
+    switch (requireNonNull(unit, "unit")) {
     case YEAR:
     case DAY:
     default:
@@ -1390,8 +1389,8 @@ public class SqlIntervalQualifier extends SqlNode {
   private CalciteContextException invalidValueException(SqlParserPos pos,
       String value) {
     return SqlUtil.newContextException(pos,
-        RESOURCE.unsupportedIntervalLiteral(
-            "'" + value + "'", "INTERVAL " + toString()));
+        RESOURCE.unsupportedIntervalLiteral("'" + value + "'",
+            "INTERVAL " + this));
   }
 
   private static CalciteContextException fieldExceedsPrecisionException(
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlJdbcDataTypeName.java b/core/src/main/java/org/apache/calcite/sql/SqlJdbcDataTypeName.java
index 7046fee075..cf62279416 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlJdbcDataTypeName.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlJdbcDataTypeName.java
@@ -22,6 +22,10 @@ import org.apache.calcite.sql.type.SqlTypeName;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
+import static java.util.Objects.requireNonNull;
+
 /**
  * Defines the name of the types which can occur as a type argument
  * in a JDBC <code>{fn CONVERT(value, type)}</code> function.
@@ -78,19 +82,20 @@ public enum SqlJdbcDataTypeName implements Symbolizable {
     this(null, range);
   }
 
-  SqlJdbcDataTypeName(@Nullable SqlTypeName typeName, @Nullable TimeUnitRange range) {
-    assert (typeName == null) != (range == null);
+  SqlJdbcDataTypeName(@Nullable SqlTypeName typeName,
+      @Nullable TimeUnitRange range) {
     this.typeName = typeName;
     this.range = range;
+    checkArgument((typeName == null) != (range == null));
   }
 
   /** Creates a parse tree node for a type identifier of this name. */
   public SqlNode createDataType(SqlParserPos pos) {
     if (typeName != null) {
-      assert range == null;
+      checkArgument(range == null);
       return new SqlDataTypeSpec(new SqlBasicTypeNameSpec(typeName, pos), pos);
     } else {
-      assert range != null;
+      requireNonNull(range, "range");
       return new SqlIntervalQualifier(range.startUnit, range.endUnit, pos);
     }
   }
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlLambda.java b/core/src/main/java/org/apache/calcite/sql/SqlLambda.java
index f0d7d5fd0a..c0f8b2b145 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlLambda.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlLambda.java
@@ -26,12 +26,13 @@ import org.apache.calcite.util.UnmodifiableArrayList;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
 
 import static com.google.common.collect.ImmutableList.toImmutableList;
 
 import static org.apache.calcite.sql.SqlPivot.stripList;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A <code>SqlLambda</code> is a node of a parse tree which
  * represents a lambda expression.
@@ -67,10 +68,10 @@ public class SqlLambda extends SqlCall {
   @Override public void setOperand(int i, @Nullable SqlNode operand) {
     switch (i) {
     case 0:
-      parameters = Objects.requireNonNull((SqlNodeList) operand, "parameters");
+      parameters = requireNonNull((SqlNodeList) operand, "parameters");
       break;
     case 1:
-      expression = Objects.requireNonNull(operand, "operand");
+      expression = requireNonNull(operand, "operand");
       break;
     default:
       throw new AssertionError(i);
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java
index 272c0d135c..8a4a6a8a72 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java
@@ -50,9 +50,12 @@ import java.nio.charset.UnsupportedCharsetException;
 import java.util.Calendar;
 import java.util.Objects;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.lang.Integer.parseInt;
 import static java.util.Objects.requireNonNull;
 
 /**
@@ -177,9 +180,8 @@ public class SqlLiteral extends SqlNode {
       SqlParserPos pos) {
     super(pos);
     this.value = value;
-    this.typeName = typeName;
-    assert typeName != null;
-    assert valueMatchesType(value, typeName);
+    this.typeName = requireNonNull(typeName, "typeName");
+    checkArgument(valueMatchesType(value, typeName));
   }
 
   //~ Methods ----------------------------------------------------------------
@@ -834,7 +836,7 @@ public class SqlLiteral extends SqlNode {
     case VARBINARY: // should never happen
 
     default:
-      throw Util.needToImplement(toString() + ", operand=" + value);
+      throw Util.needToImplement(this + ", operand=" + value);
     }
   }
 
@@ -1101,7 +1103,7 @@ public class SqlLiteral extends SqlNode {
         final String u = s.substring(i + 1, i + 5);
         final int v;
         try {
-          v = Integer.parseInt(u, 16);
+          v = parseInt(u, 16);
         } catch (NumberFormatException ex) {
           throw SqlUtil.newContextException(getParserPosition(),
               RESOURCE.unicodeEscapeMalformed(i));
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlMatchRecognize.java b/core/src/main/java/org/apache/calcite/sql/SqlMatchRecognize.java
index 24de92d989..ffd37c04d2 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlMatchRecognize.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlMatchRecognize.java
@@ -26,10 +26,11 @@ import org.apache.calcite.util.ImmutableNullableList;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * SqlNode for MATCH_RECOGNIZE clause.
  */
@@ -77,20 +78,20 @@ public class SqlMatchRecognize extends SqlCall {
       @Nullable SqlLiteral rowsPerMatch, SqlNodeList partitionList,
       SqlNodeList orderList, @Nullable SqlLiteral interval) {
     super(pos);
-    this.tableRef = Objects.requireNonNull(tableRef, "tableRef");
-    this.pattern = Objects.requireNonNull(pattern, "pattern");
+    this.tableRef = requireNonNull(tableRef, "tableRef");
+    this.pattern = requireNonNull(pattern, "pattern");
     this.strictStart = strictStart;
     this.strictEnd = strictEnd;
-    this.patternDefList = Objects.requireNonNull(patternDefList, "patternDefList");
+    this.patternDefList = requireNonNull(patternDefList, "patternDefList");
     checkArgument(!patternDefList.isEmpty());
-    this.measureList = Objects.requireNonNull(measureList, "measureList");
+    this.measureList = requireNonNull(measureList, "measureList");
     this.after = after;
     this.subsetList = subsetList;
     checkArgument(rowsPerMatch == null
         || rowsPerMatch.value instanceof RowsPerMatchOption);
     this.rowsPerMatch = rowsPerMatch;
-    this.partitionList = Objects.requireNonNull(partitionList, "partitionList");
-    this.orderList = Objects.requireNonNull(orderList, "orderList");
+    this.partitionList = requireNonNull(partitionList, "partitionList");
+    this.orderList = requireNonNull(orderList, "orderList");
     this.interval = interval;
   }
 
@@ -124,7 +125,7 @@ public class SqlMatchRecognize extends SqlCall {
   @Override public void setOperand(int i, @Nullable SqlNode operand) {
     switch (i) {
     case OPERAND_TABLE_REF:
-      tableRef = Objects.requireNonNull(operand, "operand");
+      tableRef = requireNonNull(operand, "operand");
       break;
     case OPERAND_PATTERN:
       pattern = operand;
@@ -136,11 +137,11 @@ public class SqlMatchRecognize extends SqlCall {
       strictEnd = (SqlLiteral) operand;
       break;
     case OPERAND_PATTERN_DEFINES:
-      patternDefList = Objects.requireNonNull((SqlNodeList) operand);
+      patternDefList = requireNonNull((SqlNodeList) operand);
       checkArgument(!patternDefList.isEmpty());
       break;
     case OPERAND_MEASURES:
-      measureList = Objects.requireNonNull((SqlNodeList) operand);
+      measureList = requireNonNull((SqlNodeList) operand);
       break;
     case OPERAND_AFTER:
       after = operand;
@@ -322,7 +323,7 @@ public class SqlMatchRecognize extends SqlCall {
       pattern.tableRef.unparse(writer, 0, 0);
       final SqlWriter.Frame mrFrame = writer.startFunCall("MATCH_RECOGNIZE");
 
-      if (pattern.partitionList != null && pattern.partitionList.size() > 0) {
+      if (!pattern.partitionList.isEmpty()) {
         writer.newlineAndIndent();
         writer.sep("PARTITION BY");
         final SqlWriter.Frame partitionFrame = writer.startList("", "");
@@ -330,14 +331,14 @@ public class SqlMatchRecognize extends SqlCall {
         writer.endList(partitionFrame);
       }
 
-      if (pattern.orderList != null && pattern.orderList.size() > 0) {
+      if (!pattern.orderList.isEmpty()) {
         writer.newlineAndIndent();
         writer.sep("ORDER BY");
         writer.list(SqlWriter.FrameTypeEnum.ORDER_BY_LIST, SqlWriter.COMMA,
             pattern.orderList);
       }
 
-      if (pattern.measureList != null && pattern.measureList.size() > 0) {
+      if (!pattern.measureList.isEmpty()) {
         writer.newlineAndIndent();
         writer.sep("MEASURES");
         final SqlWriter.Frame measureFrame = writer.startList("", "");
@@ -376,7 +377,7 @@ public class SqlMatchRecognize extends SqlCall {
         interval.unparse(writer, 0, 0);
       }
 
-      if (pattern.subsetList != null && pattern.subsetList.size() > 0) {
+      if (!pattern.subsetList.isEmpty()) {
         writer.newlineAndIndent();
         writer.sep("SUBSET");
         SqlWriter.Frame subsetFrame = writer.startList("", "");
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlNode.java b/core/src/main/java/org/apache/calcite/sql/SqlNode.java
index a66f21d90e..fa642101b4 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlNode.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlNode.java
@@ -33,11 +33,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
-import java.util.Objects;
 import java.util.Set;
 import java.util.function.UnaryOperator;
 import java.util.stream.Collector;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A <code>SqlNode</code> is a SQL parse tree.
  *
@@ -62,7 +63,7 @@ public abstract class SqlNode implements Cloneable {
    * @param pos Parser position, must not be null.
    */
   SqlNode(SqlParserPos pos) {
-    this.pos = Objects.requireNonNull(pos, "pos");
+    this.pos = requireNonNull(pos, "pos");
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlNodeList.java b/core/src/main/java/org/apache/calcite/sql/SqlNodeList.java
index dfa0486e30..507b74a691 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlNodeList.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlNodeList.java
@@ -32,12 +32,13 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
-import java.util.Objects;
 import java.util.RandomAccess;
 import java.util.function.Consumer;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A <code>SqlNodeList</code> is a list of {@link SqlNode}s. It is also a
  * {@link SqlNode}, so may appear in a parse tree.
@@ -79,7 +80,7 @@ public class SqlNodeList extends SqlNode implements List<SqlNode>, RandomAccess
    * should allow O(1) access to elements. */
   private SqlNodeList(SqlParserPos pos, List<@Nullable SqlNode> list) {
     super(pos);
-    this.list = Objects.requireNonNull(list, "list");
+    this.list = requireNonNull(list, "list");
   }
 
   /**
@@ -123,7 +124,7 @@ public class SqlNodeList extends SqlNode implements List<SqlNode>, RandomAccess
   }
 
   @Override public boolean isEmpty() {
-    return list.isEmpty();
+    return list.size() == 0;
   }
 
   @Override public int size() {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlNumericLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlNumericLiteral.java
index 6867d199f0..bcb5064a18 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlNumericLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlNumericLiteral.java
@@ -35,9 +35,9 @@ import static java.util.Objects.requireNonNull;
 public class SqlNumericLiteral extends SqlLiteral {
   //~ Instance fields --------------------------------------------------------
 
-  private @Nullable Integer prec;
-  private @Nullable Integer scale;
-  private boolean isExact;
+  private final @Nullable Integer prec;
+  private final @Nullable Integer scale;
+  private final boolean exact;
 
   //~ Constructors -----------------------------------------------------------
 
@@ -45,15 +45,15 @@ public class SqlNumericLiteral extends SqlLiteral {
       BigDecimal value,
       @Nullable Integer prec,
       @Nullable Integer scale,
-      boolean isExact,
+      boolean exact,
       SqlParserPos pos) {
     super(
         value,
-        isExact ? SqlTypeName.DECIMAL : SqlTypeName.DOUBLE,
+        exact ? SqlTypeName.DECIMAL : SqlTypeName.DOUBLE,
         pos);
     this.prec = prec;
     this.scale = scale;
-    this.isExact = isExact;
+    this.exact = exact;
   }
 
   //~ Methods ----------------------------------------------------------------
@@ -72,12 +72,12 @@ public class SqlNumericLiteral extends SqlLiteral {
   }
 
   public boolean isExact() {
-    return isExact;
+    return exact;
   }
 
   @Override public SqlNumericLiteral clone(SqlParserPos pos) {
     return new SqlNumericLiteral(getValueNonNull(), getPrec(), getScale(),
-        isExact, pos);
+        exact, pos);
   }
 
   @Override public void unparse(
@@ -89,14 +89,14 @@ public class SqlNumericLiteral extends SqlLiteral {
 
   @Override public String toValue() {
     final BigDecimal bd = getValueNonNull();
-    if (isExact) {
+    if (exact) {
       return bd.toPlainString();
     }
     return Util.toScientificNotation(bd);
   }
 
   @Override public RelDataType createSqlType(RelDataTypeFactory typeFactory) {
-    if (isExact) {
+    if (exact) {
       int scaleValue = requireNonNull(scale, "scale");
       if (0 == scaleValue) {
         try {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlOperator.java
index 342113b306..44d0ce9e39 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlOperator.java
@@ -78,7 +78,7 @@ import static java.util.Objects.requireNonNull;
 public abstract class SqlOperator {
   //~ Static fields/initializers ---------------------------------------------
 
-  public static final String NL = System.getProperty("line.separator");
+  public static final String NL = System.lineSeparator();
 
   /**
    * Maximum precedence.
@@ -134,9 +134,8 @@ public abstract class SqlOperator {
       @Nullable SqlReturnTypeInference returnTypeInference,
       @Nullable SqlOperandTypeInference operandTypeInference,
       @Nullable SqlOperandTypeChecker operandTypeChecker) {
-    assert kind != null;
     this.name = name;
-    this.kind = kind;
+    this.kind = requireNonNull(kind, "kind");
     this.leftPrec = leftPrecedence;
     this.rightPrec = rightPrecedence;
     this.returnTypeInference = returnTypeInference;
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlPivot.java b/core/src/main/java/org/apache/calcite/sql/SqlPivot.java
index 6a082b1433..2d0f3652de 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlPivot.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlPivot.java
@@ -30,7 +30,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.HashSet;
 import java.util.List;
-import java.util.Objects;
 import java.util.Set;
 import java.util.function.BiConsumer;
 import java.util.stream.Collectors;
@@ -61,10 +60,10 @@ public class SqlPivot extends SqlCall {
   public SqlPivot(SqlParserPos pos, SqlNode query, SqlNodeList aggList,
       SqlNodeList axisList, SqlNodeList inList) {
     super(pos);
-    this.query = Objects.requireNonNull(query, "query");
-    this.aggList = Objects.requireNonNull(aggList, "aggList");
-    this.axisList = Objects.requireNonNull(axisList, "axisList");
-    this.inList = Objects.requireNonNull(inList, "inList");
+    this.query = requireNonNull(query, "query");
+    this.aggList = requireNonNull(aggList, "aggList");
+    this.axisList = requireNonNull(axisList, "axisList");
+    this.inList = requireNonNull(inList, "inList");
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlRowTypeNameSpec.java b/core/src/main/java/org/apache/calcite/sql/SqlRowTypeNameSpec.java
index e23c406665..491148bb23 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlRowTypeNameSpec.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlRowTypeNameSpec.java
@@ -25,9 +25,10 @@ import org.apache.calcite.util.Litmus;
 import org.apache.calcite.util.Pair;
 
 import java.util.List;
-import java.util.Objects;
 import java.util.stream.Collectors;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A sql type name specification of row type.
  *
@@ -66,11 +67,9 @@ public class SqlRowTypeNameSpec extends SqlTypeNameSpec {
       List<SqlIdentifier> fieldNames,
       List<SqlDataTypeSpec> fieldTypes) {
     super(new SqlIdentifier(SqlTypeName.ROW.getName(), pos), pos);
-    Objects.requireNonNull(fieldNames, "fieldNames");
-    Objects.requireNonNull(fieldTypes, "fieldTypes");
-    assert fieldNames.size() > 0; // there must be at least one field.
-    this.fieldNames = fieldNames;
-    this.fieldTypes = fieldTypes;
+    this.fieldNames = requireNonNull(fieldNames, "fieldNames");
+    this.fieldTypes = requireNonNull(fieldTypes, "fieldTypes");
+    assert !fieldNames.isEmpty(); // there must be at least one field.
   }
 
   public List<SqlIdentifier> getFieldNames() {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlSelect.java b/core/src/main/java/org/apache/calcite/sql/SqlSelect.java
index 1d81fa7dbf..3203bc84d5 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlSelect.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlSelect.java
@@ -275,7 +275,7 @@ public class SqlSelect extends SqlCall {
   @EnsuresNonNullIf(expression = "hints", result = true)
   public boolean hasHints() {
     // The hints may be passed as null explicitly.
-    return this.hints != null && this.hints.size() > 0;
+    return this.hints != null && !this.hints.isEmpty();
   }
 
   @Override public void validate(SqlValidator validator, SqlValidatorScope scope) {
@@ -307,7 +307,7 @@ public class SqlSelect extends SqlCall {
   }
 
   public boolean hasOrderBy() {
-    return orderBy != null && orderBy.size() != 0;
+    return orderBy != null && !orderBy.isEmpty();
   }
 
   public boolean hasWhere() {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlSelectOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlSelectOperator.java
index 0ced990139..b8db2d8f5a 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlSelectOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlSelectOperator.java
@@ -206,7 +206,7 @@ public class SqlSelectOperator extends SqlOperator {
     }
     if (select.groupBy != null) {
       SqlNodeList groupBy =
-          select.groupBy.size() == 0 ? SqlNodeList.SINGLETON_EMPTY
+          select.groupBy.isEmpty() ? SqlNodeList.SINGLETON_EMPTY
               : select.groupBy;
       // if the DISTINCT keyword of GROUP BY is present it can be the only item
       if (groupBy.size() == 1 && groupBy.get(0) != null
@@ -224,7 +224,7 @@ public class SqlSelectOperator extends SqlOperator {
       writer.sep("HAVING");
       select.having.unparse(writer, 0, 0);
     }
-    if (select.windowDecls.size() > 0) {
+    if (!select.windowDecls.isEmpty()) {
       writer.sep("WINDOW");
       writer.list(SqlWriter.FrameTypeEnum.WINDOW_DECL_LIST, SqlWriter.COMMA,
           select.windowDecls);
@@ -233,7 +233,7 @@ public class SqlSelectOperator extends SqlOperator {
       writer.sep("QUALIFY");
       select.qualify.unparse(writer, 0, 0);
     }
-    if (select.orderBy != null && select.orderBy.size() > 0) {
+    if (select.orderBy != null && !select.orderBy.isEmpty()) {
       writer.sep("ORDER BY");
       writer.list(SqlWriter.FrameTypeEnum.ORDER_BY_LIST, SqlWriter.COMMA,
           select.orderBy);
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlSetOption.java b/core/src/main/java/org/apache/calcite/sql/SqlSetOption.java
index ff52054b63..8eb6ae8f54 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlSetOption.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlSetOption.java
@@ -97,9 +97,8 @@ public class SqlSetOption extends SqlAlter {
       @Nullable SqlNode value) {
     super(pos, scope);
     this.scope = scope;
-    this.name = name;
+    this.name = requireNonNull(name, "name");
     this.value = value;
-    assert name != null;
   }
 
   @Override public SqlKind getKind() {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlSetSemanticsTableOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlSetSemanticsTableOperator.java
index 310af7c880..84e35075f1 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlSetSemanticsTableOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlSetSemanticsTableOperator.java
@@ -25,6 +25,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * SetSemanticsTable appears as an parameter in a table function.
  * It represents as an input table with set semantics.
@@ -63,14 +65,14 @@ public class SqlSetSemanticsTableOperator extends SqlInternalOperator {
     call.operand(0).unparse(writer, 0, 0);
 
     SqlNodeList partitionList = call.operand(1);
-    if (partitionList.size() > 0) {
+    if (!partitionList.isEmpty()) {
       writer.sep("PARTITION BY");
       final SqlWriter.Frame partitionFrame = writer.startList("", "");
       partitionList.unparse(writer, 0, 0);
       writer.endList(partitionFrame);
     }
     SqlNodeList orderList = call.operand(2);
-    if (orderList.size() > 0) {
+    if (!orderList.isEmpty()) {
       writer.sep("ORDER BY");
       writer.list(
           SqlWriter.FrameTypeEnum.ORDER_BY_LIST,
@@ -83,9 +85,7 @@ public class SqlSetSemanticsTableOperator extends SqlInternalOperator {
       SqlValidator validator,
       SqlValidatorScope scope, SqlCall call) {
     final List<SqlNode> operands = call.getOperandList();
-    RelDataType tableType = validator.deriveType(scope, operands.get(0));
-    assert tableType != null;
-    return tableType;
+    return requireNonNull(validator.deriveType(scope, operands.get(0)));
   }
 
   @Override public boolean argumentMustBeScalar(int ordinal) {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlSnapshot.java b/core/src/main/java/org/apache/calcite/sql/SqlSnapshot.java
index 4ccf3d1879..adf9f27f9f 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlSnapshot.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlSnapshot.java
@@ -24,7 +24,8 @@ import org.apache.calcite.util.ImmutableNullableList;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Parse tree node for "{@code FOR SYSTEM_TIME AS OF}" temporal clause.
@@ -41,8 +42,8 @@ public class SqlSnapshot extends SqlCall {
   /** Creates a SqlSnapshot. */
   public SqlSnapshot(SqlParserPos pos, SqlNode tableRef, SqlNode period) {
     super(pos);
-    this.tableRef = Objects.requireNonNull(tableRef, "tableRef");
-    this.period = Objects.requireNonNull(period, "period");
+    this.tableRef = requireNonNull(tableRef, "tableRef");
+    this.period = requireNonNull(period, "period");
   }
 
   // ~ Methods
@@ -66,10 +67,10 @@ public class SqlSnapshot extends SqlCall {
   @Override public void setOperand(int i, @Nullable SqlNode operand) {
     switch (i) {
     case OPERAND_TABLE_REF:
-      tableRef = Objects.requireNonNull(operand, "operand");
+      tableRef = requireNonNull(operand, "operand");
       break;
     case OPERAND_PERIOD:
-      period = Objects.requireNonNull(operand, "operand");
+      period = requireNonNull(operand, "operand");
       break;
     default:
       throw new AssertionError(i);
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlSpatialTypeOperatorTable.java b/core/src/main/java/org/apache/calcite/sql/SqlSpatialTypeOperatorTable.java
index 8ab7dc7d88..6d0f920d2a 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlSpatialTypeOperatorTable.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlSpatialTypeOperatorTable.java
@@ -36,7 +36,8 @@ import com.google.common.collect.ImmutableList;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Implementation of {@link org.apache.calcite.sql.SqlSpatialTypeOperatorTable} containing
@@ -60,15 +61,12 @@ public class SqlSpatialTypeOperatorTable implements SqlOperatorTable {
         SqlSpatialTypeFunctions.class.getName(), "*", true);
 
     // Register the spatial aggregate functions.
-    schema.add(
-        "ST_UNION", Objects.requireNonNull(
-        AggregateFunctionImpl.create(UnionOperation.class)));
-    schema.add(
-        "ST_ACCUM", Objects.requireNonNull(
-        AggregateFunctionImpl.create(AccumOperation.class)));
-    schema.add(
-        "ST_COLLECT", Objects.requireNonNull(
-        AggregateFunctionImpl.create(CollectOperation.class)));
+    schema.add("ST_UNION",
+        requireNonNull(AggregateFunctionImpl.create(UnionOperation.class)));
+    schema.add("ST_ACCUM",
+        requireNonNull(AggregateFunctionImpl.create(AccumOperation.class)));
+    schema.add("ST_COLLECT",
+        requireNonNull(AggregateFunctionImpl.create(CollectOperation.class)));
 
     // Create a catalog reader to retrieve the operators.
     CalciteCatalogReader catalogReader =
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlTableRef.java b/core/src/main/java/org/apache/calcite/sql/SqlTableRef.java
index 1d4896d584..8d164b77a1 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlTableRef.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlTableRef.java
@@ -72,7 +72,7 @@ public class SqlTableRef extends SqlCall {
 
   @Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
     tableName.unparse(writer, leftPrec, rightPrec);
-    if (this.hints != null && this.hints.size() > 0) {
+    if (!this.hints.isEmpty()) {
       writer.getDialect().unparseTableScanHints(writer, this.hints, leftPrec, rightPrec);
     }
   }
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlTimeLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlTimeLiteral.java
index 953ca8611f..40da46d50d 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlTimeLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlTimeLiteral.java
@@ -20,10 +20,10 @@ import org.apache.calcite.sql.parser.SqlParserPos;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.TimeString;
 
-import java.util.Objects;
-
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A SQL literal representing a TIME value, for example <code>TIME
  * '14:33:44.567'</code>.
@@ -43,7 +43,7 @@ public class SqlTimeLiteral extends SqlAbstractDateTimeLiteral {
 
   /** Converts this literal to a {@link TimeString}. */
   protected TimeString getTime() {
-    return (TimeString) Objects.requireNonNull(value, "value");
+    return (TimeString) requireNonNull(value, "value");
   }
 
   @Override public SqlTimeLiteral clone(SqlParserPos pos) {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlTimeTzLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlTimeTzLiteral.java
index e13a742d35..0713c71167 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlTimeTzLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlTimeTzLiteral.java
@@ -20,10 +20,10 @@ import org.apache.calcite.sql.parser.SqlParserPos;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.TimeWithTimeZoneString;
 
-import java.util.Objects;
-
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A SQL literal representing a TIME WITH TIME ZONE value, for example <code>TIME WITH TIME ZONE
  * '14:33:44.567 GMT+08'</code>.
@@ -43,7 +43,7 @@ public class SqlTimeTzLiteral extends SqlAbstractDateTimeLiteral {
 
   /** Converts this literal to a {@link TimeWithTimeZoneString}. */
   protected TimeWithTimeZoneString getTime() {
-    return (TimeWithTimeZoneString) Objects.requireNonNull(value, "value");
+    return (TimeWithTimeZoneString) requireNonNull(value, "value");
   }
 
   @Override public SqlTimeTzLiteral clone(SqlParserPos pos) {
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlTimestampLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlTimestampLiteral.java
index 8d1e6ec636..a298b1533c 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlTimestampLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlTimestampLiteral.java
@@ -20,10 +20,10 @@ import org.apache.calcite.sql.parser.SqlParserPos;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.TimestampString;
 
-import java.util.Objects;
-
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A SQL literal representing a TIMESTAMP value, for example <code>TIMESTAMP
  * '1969-07-21 03:15'</code>.
@@ -45,7 +45,7 @@ public class SqlTimestampLiteral extends SqlAbstractDateTimeLiteral {
 
   @Override public SqlTimestampLiteral clone(SqlParserPos pos) {
     return new SqlTimestampLiteral(
-        (TimestampString) Objects.requireNonNull(value, "value"),
+        (TimestampString) requireNonNull(value, "value"),
         precision,
         getTypeName(), pos);
   }
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlTimestampTzLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlTimestampTzLiteral.java
index d10ba742df..ee5392eb13 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlTimestampTzLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlTimestampTzLiteral.java
@@ -20,10 +20,10 @@ import org.apache.calcite.sql.parser.SqlParserPos;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.TimestampWithTimeZoneString;
 
-import java.util.Objects;
-
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A SQL literal representing a TIMESTAMP WITH TIME ZONE value, for example <code>TIMESTAMP
  * '1969-07-21 03:15 GMT+00:00'</code>.
@@ -58,7 +58,7 @@ public class SqlTimestampTzLiteral extends SqlAbstractDateTimeLiteral {
   }
 
   TimestampWithTimeZoneString getTimestampTz() {
-    return (TimestampWithTimeZoneString) Objects.requireNonNull(value, "value");
+    return (TimestampWithTimeZoneString) requireNonNull(value, "value");
   }
 
   @Override public void unparse(
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlTypeConstructorFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlTypeConstructorFunction.java
index 216ebc783d..55c0a8feba 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlTypeConstructorFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlTypeConstructorFunction.java
@@ -27,7 +27,7 @@ import org.apache.calcite.sql.type.ExplicitOperandTypeChecker;
  */
 public class SqlTypeConstructorFunction extends SqlFunction {
 
-  private RelDataType type;
+  private final RelDataType type;
 
   /**
    * Creates a constructor function for types.
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlUnpivot.java b/core/src/main/java/org/apache/calcite/sql/SqlUnpivot.java
index 7770908343..528b9ee57d 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlUnpivot.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlUnpivot.java
@@ -26,11 +26,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.HashSet;
 import java.util.List;
-import java.util.Objects;
 import java.util.Set;
 import java.util.function.BiConsumer;
 import java.util.function.Consumer;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Parse tree node that represents UNPIVOT applied to a table reference
  * (or sub-query).
@@ -65,11 +66,11 @@ public class SqlUnpivot extends SqlCall {
   public SqlUnpivot(SqlParserPos pos, SqlNode query, boolean includeNulls,
       SqlNodeList measureList, SqlNodeList axisList, SqlNodeList inList) {
     super(pos);
-    this.query = Objects.requireNonNull(query, "query");
+    this.query = requireNonNull(query, "query");
     this.includeNulls = includeNulls;
-    this.measureList = Objects.requireNonNull(measureList, "measureList");
-    this.axisList = Objects.requireNonNull(axisList, "axisList");
-    this.inList = Objects.requireNonNull(inList, "inList");
+    this.measureList = requireNonNull(measureList, "measureList");
+    this.axisList = requireNonNull(axisList, "axisList");
+    this.inList = requireNonNull(inList, "inList");
   }
 
   //~ Methods ----------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlUpdate.java b/core/src/main/java/org/apache/calcite/sql/SqlUpdate.java
index 50e051dea3..a827e4ccbd 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlUpdate.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlUpdate.java
@@ -28,6 +28,8 @@ import org.checkerframework.dataflow.qual.Pure;
 
 import java.util.List;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * A <code>SqlUpdate</code> is a node of a parse tree which represents an UPDATE
  * statement.
@@ -53,9 +55,11 @@ public class SqlUpdate extends SqlCall {
       @Nullable SqlSelect sourceSelect,
       @Nullable SqlIdentifier alias) {
     super(pos);
-    this.targetTable = targetTable;
-    this.targetColumnList = targetColumnList;
-    this.sourceExpressionList = sourceExpressionList;
+    this.targetTable = requireNonNull(targetTable, "targetTable");
+    this.targetColumnList =
+        requireNonNull(targetColumnList, "targetColumnList");
+    this.sourceExpressionList =
+        requireNonNull(sourceExpressionList, "sourceExpressionList");
     this.condition = condition;
     this.sourceSelect = sourceSelect;
     assert sourceExpressionList.size() == targetColumnList.size();
@@ -86,16 +90,16 @@ public class SqlUpdate extends SqlCall {
       targetTable = operand;
       break;
     case 1:
-      targetColumnList = (SqlNodeList) operand;
+      targetColumnList = requireNonNull((SqlNodeList) operand);
       break;
     case 2:
-      sourceExpressionList = (SqlNodeList) operand;
+      sourceExpressionList = requireNonNull((SqlNodeList) operand);
       break;
     case 3:
       condition = operand;
       break;
     case 4:
-      sourceExpressionList = (SqlNodeList) operand;
+      sourceExpressionList = requireNonNull((SqlNodeList) operand);
       break;
     case 5:
       alias = (SqlIdentifier) operand;
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlUtil.java b/core/src/main/java/org/apache/calcite/sql/SqlUtil.java
index d0c9157b56..5cb4c9287f 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlUtil.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlUtil.java
@@ -62,20 +62,21 @@ import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.UnsupportedCharsetException;
 import java.sql.DatabaseMetaData;
-import java.sql.SQLException;
 import java.text.MessageFormat;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
-import java.util.Objects;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Contains utility functions related to SQL parsing, all static.
  */
@@ -127,7 +128,9 @@ public abstract class SqlUtil {
       SqlSelect query,
       int ordinal) {
     SqlNode from = query.getFrom();
-    assert from != null : "from must not be null for " + query;
+    if (from == null) {
+      throw new AssertionError("from must not be null for " + query);
+    }
     ArrayList<SqlNode> list = flatten(from);
     return list.get(ordinal);
   }
@@ -158,9 +161,7 @@ public abstract class SqlUtil {
   /** Converts a SqlNode array to a SqlNodeList. */
   public static SqlNodeList toNodeList(SqlNode[] operands) {
     SqlNodeList ret = new SqlNodeList(SqlParserPos.ZERO);
-    for (SqlNode node : operands) {
-      ret.add(node);
-    }
+    Collections.addAll(ret, operands);
     return ret;
   }
 
@@ -206,10 +207,8 @@ public abstract class SqlUtil {
     if (allowCast && node != null) {
       if (node.getKind() == SqlKind.CAST) {
         SqlCall call = (SqlCall) node;
-        if (isNullLiteral(call.operand(0), false)) {
-          // node is "CAST(NULL as type)"
-          return true;
-        }
+        // node is "CAST(NULL as type)"
+        return isNullLiteral(call.operand(0), false);
       }
     }
     return false;
@@ -244,7 +243,7 @@ public abstract class SqlUtil {
    * @return Whether the node is a literal
    */
   public static boolean isLiteral(SqlNode node, boolean allowCast) {
-    assert node != null;
+    requireNonNull(node, "node");
     if (node instanceof SqlLiteral) {
       return true;
     }
@@ -288,7 +287,7 @@ public abstract class SqlUtil {
    * @return Whether the node is a literal chain
    */
   public static boolean isLiteralChain(SqlNode node) {
-    assert node != null;
+    requireNonNull(node, "node");
     if (node instanceof SqlCall) {
       SqlCall call = (SqlCall) node;
       return call.getKind() == SqlKind.LITERAL_CHAIN;
@@ -418,7 +417,7 @@ public abstract class SqlUtil {
         writer.sep(".");
         final String name = identifier.names.get(i);
         final SqlParserPos pos = identifier.getComponentParserPosition(i);
-        if (name.equals("")) {
+        if (name.isEmpty()) {
           writer.print("*");
           writer.setNeedWhitespace(true);
         } else {
@@ -519,7 +518,7 @@ public abstract class SqlUtil {
   private static Iterator<SqlOperator> filterOperatorRoutinesByKind(
       Iterator<SqlOperator> routines, final SqlKind sqlKind) {
     return Iterators.filter(routines,
-        operator -> Objects.requireNonNull(operator, "operator")
+        operator -> requireNonNull(operator, "operator")
             .getKind().getFunctionKind() == sqlKind);
   }
 
@@ -630,7 +629,8 @@ public abstract class SqlUtil {
           Predicates.instanceOf(SqlFunction.class));
     default:
       return Iterators.filter(sqlOperators.iterator(),
-          operator -> Objects.requireNonNull(operator, "operator").getSyntax() == syntax);
+          operator ->
+              requireNonNull(operator, "operator").getSyntax() == syntax);
     }
   }
 
@@ -638,7 +638,7 @@ public abstract class SqlUtil {
       Iterator<SqlOperator> routines,
       final List<RelDataType> argTypes) {
     return Iterators.filter(routines,
-        operator -> Objects.requireNonNull(operator, "operator")
+        operator -> requireNonNull(operator, "operator")
             .getOperandCountRange().isValidCount(argTypes.size()));
   }
 
@@ -661,7 +661,7 @@ public abstract class SqlUtil {
         Iterators.filter(routines, SqlFunction.class),
         function -> {
           SqlOperandTypeChecker operandTypeChecker =
-              Objects.requireNonNull(function, "function").getOperandTypeChecker();
+              requireNonNull(function, "function").getOperandTypeChecker();
           if (operandTypeChecker == null
               || !operandTypeChecker.isFixedParameters()) {
             // no parameter information for builtins; keep for now,
@@ -806,15 +806,17 @@ public abstract class SqlUtil {
     switch (query.getKind()) {
     case SELECT:
       SqlSelect select = (SqlSelect) query;
-      final SqlNode from = stripAs(select.getFrom());
-      if (from != null && from.getKind() == SqlKind.VALUES) {
-        // They wrote "VALUES (x, y)", but the validator has
-        // converted this into "SELECT * FROM VALUES (x, y)".
-        return getSelectListItem(from, i);
+      SqlNode from = select.getFrom();
+      if (from != null) {
+        from = stripAs(from);
+        if (from.getKind() == SqlKind.VALUES) {
+          // They wrote "VALUES (x, y)", but the validator has
+          // converted this into "SELECT * FROM VALUES (x, y)".
+          return getSelectListItem(from, i);
+        }
       }
-      final SqlNodeList fields = select.getSelectList();
 
-      assert fields != null : "fields must not be null in " + select;
+      final SqlNodeList fields = select.getSelectList();
       // Range check the index to avoid index out of range.  This
       // could be expanded to actually check to see if the select
       // list is a "*"
@@ -848,8 +850,9 @@ public abstract class SqlUtil {
    * @return true if alias is generated by calcite, otherwise false
    */
   public static boolean isGeneratedAlias(String alias) {
-    assert alias != null;
-    return alias.toUpperCase(Locale.ROOT).startsWith(GENERATED_EXPR_ALIAS_PREFIX);
+    return requireNonNull(alias, "alias")
+        .toUpperCase(Locale.ROOT)
+        .startsWith(GENERATED_EXPR_ALIAS_PREFIX);
   }
 
   /**
@@ -1033,9 +1036,10 @@ public abstract class SqlUtil {
    *     is available in this instance of the Java virtual machine
    */
   public static Charset getCharset(String charsetName) {
-    assert charsetName != null;
-    charsetName = charsetName.toUpperCase(Locale.ROOT);
-    String javaCharsetName = translateCharacterSetName(charsetName);
+    String javaCharsetName =
+        translateCharacterSetName(
+            requireNonNull(charsetName, "charsetName")
+                .toUpperCase(Locale.ROOT));
     if (javaCharsetName == null) {
       throw new UnsupportedCharsetException(charsetName);
     }
@@ -1098,7 +1102,7 @@ public abstract class SqlUtil {
       throw new AssertionError("not found: " + predicate + " in " + root);
     } catch (Util.FoundOne e) {
       //noinspection unchecked
-      return (ImmutableList<SqlNode>) Objects.requireNonNull(
+      return (ImmutableList<SqlNode>) requireNonNull(
           e.getNode(),
           "Genealogist result");
     }
@@ -1116,7 +1120,7 @@ public abstract class SqlUtil {
    */
   public static List<RelHint> getRelHint(HintStrategyTable hintStrategies,
       @Nullable SqlNodeList sqlHints) {
-    if (sqlHints == null || sqlHints.size() == 0) {
+    if (sqlHints == null || sqlHints.isEmpty()) {
       return ImmutableList.of();
     }
     final ImmutableList.Builder<RelHint> relHints = ImmutableList.builder();
@@ -1162,7 +1166,7 @@ public abstract class SqlUtil {
       List<RelHint> hints,
       Hintable rel) {
     final List<RelHint> relHints = hintStrategies.apply(hints, (RelNode) rel);
-    if (relHints.size() > 0) {
+    if (!relHints.isEmpty()) {
       return rel.attachHints(relHints);
     }
     return (RelNode) rel;
@@ -1303,11 +1307,11 @@ public abstract class SqlUtil {
       this.identifierQuoteString = identifierQuoteString;
     }
 
-    public String getDatabaseProductName() throws SQLException {
+    public String getDatabaseProductName() {
       return databaseProductName;
     }
 
-    public String getIdentifierQuoteString() throws SQLException {
+    public String getIdentifierQuoteString() {
       return identifierQuoteString;
     }
   }
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlWindow.java b/core/src/main/java/org/apache/calcite/sql/SqlWindow.java
index 3f25c4d6e1..6bbfc0087f 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlWindow.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlWindow.java
@@ -45,6 +45,8 @@ import java.util.List;
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * SQL window specification.
  *
@@ -130,8 +132,8 @@ public class SqlWindow extends SqlCall {
     super(pos);
     this.declName = declName;
     this.refName = refName;
-    this.partitionList = partitionList;
-    this.orderList = orderList;
+    this.partitionList = requireNonNull(partitionList, "partitionList");
+    this.orderList = requireNonNull(orderList, "orderList");
     this.isRows = isRows;
     this.lowerBound = lowerBound;
     this.upperBound = upperBound;
@@ -141,8 +143,6 @@ public class SqlWindow extends SqlCall {
     assert exclude.symbolValue(Exclusion.class) == Exclusion.EXCLUDE_NO_OTHER
         || (lowerBound != null || upperBound != null);
     assert declName == null || declName.isSimple();
-    assert partitionList != null;
-    assert orderList != null;
   }
 
   public static SqlWindow create(@Nullable SqlIdentifier declName, @Nullable SqlIdentifier refName,
@@ -496,7 +496,7 @@ public class SqlWindow extends SqlCall {
   public SqlWindow overlay(SqlWindow that, SqlValidator validator) {
     // check 7.11 rule 10c
     final SqlNodeList partitions = getPartitionList();
-    if (0 != partitions.size()) {
+    if (!partitions.isEmpty()) {
       throw validator.newValidationError(partitions.get(0),
           RESOURCE.partitionNotAllowed());
     }
@@ -504,7 +504,7 @@ public class SqlWindow extends SqlCall {
     // 7.11 rule 10d
     final SqlNodeList baseOrder = getOrderList();
     final SqlNodeList refOrder = that.getOrderList();
-    if ((0 != baseOrder.size()) && (0 != refOrder.size())) {
+    if (!baseOrder.isEmpty() && !refOrder.isEmpty()) {
       throw validator.newValidationError(baseOrder.get(0),
           RESOURCE.orderByOverlap());
     }
@@ -520,7 +520,7 @@ public class SqlWindow extends SqlCall {
     }
 
     SqlIdentifier declNameNew = declName;
-    SqlIdentifier refNameNew = refName;
+    SqlIdentifier refNameNew;
     SqlNodeList partitionListNew = partitionList;
     SqlNodeList orderListNew = orderList;
     SqlLiteral isRowsNew = isRows;
@@ -659,7 +659,7 @@ public class SqlWindow extends SqlCall {
     }
 
     // 6.10 rule 6a Function RANK & DENSE_RANK require ORDER BY clause
-    if (orderList.size() == 0
+    if (orderList.isEmpty()
         && !SqlValidatorUtil.containsMonotonic(scope)
         && windowCall != null
         && windowCall.getOperator().requiresOrder()) {
@@ -675,7 +675,7 @@ public class SqlWindow extends SqlCall {
       SqlTypeFamily orderTypeFam = null;
 
       // SQL03 7.10 Rule 11a
-      if (orderList.size() > 0) {
+      if (!orderList.isEmpty()) {
         // if order by is a compound list then range not allowed
         if (orderList.size() > 1
             && !isRows()
@@ -718,7 +718,7 @@ public class SqlWindow extends SqlCall {
 
       // Validate across boundaries. 7.10 Rule 8 a-d
       checkSpecialLiterals(this, validator);
-    } else if (orderList.size() == 0
+    } else if (orderList.isEmpty()
         && !SqlValidatorUtil.containsMonotonic(scope)
         && windowCall != null
         && windowCall.getOperator().requiresOrder()) {
@@ -731,7 +731,8 @@ public class SqlWindow extends SqlCall {
     }
   }
 
-  private boolean onlySymbolBounds(@Nullable SqlNode lowerBound, @Nullable SqlNode upperBound) {
+  private static boolean onlySymbolBounds(@Nullable SqlNode lowerBound,
+      @Nullable SqlNode upperBound) {
     return lowerBound != null && upperBound != null
         && (isCurrentRow(lowerBound) || isUnboundedPreceding(lowerBound))
         && (isCurrentRow(upperBound) || isUnboundedFollowing(upperBound));
@@ -924,13 +925,13 @@ public class SqlWindow extends SqlCall {
       return create(
           (SqlIdentifier) operands[0],
           (SqlIdentifier) operands[1],
-          (SqlNodeList) operands[2],
-          (SqlNodeList) operands[3],
-          (SqlLiteral) operands[4],
+          (SqlNodeList) requireNonNull(operands[2]),
+          (SqlNodeList) requireNonNull(operands[3]),
+          (SqlLiteral) requireNonNull(operands[4]),
           operands[5],
           operands[6],
           (SqlLiteral) operands[7],
-          (SqlLiteral) operands[8],
+          (SqlLiteral) requireNonNull(operands[8]),
           pos);
     }
 
@@ -969,13 +970,13 @@ public class SqlWindow extends SqlCall {
       if (window.refName != null) {
         window.refName.unparse(writer, 0, 0);
       }
-      if (window.partitionList.size() > 0) {
+      if (!window.partitionList.isEmpty()) {
         writer.sep("PARTITION BY");
         final SqlWriter.Frame partitionFrame = writer.startList("", "");
         window.partitionList.unparse(writer, 0, 0);
         writer.endList(partitionFrame);
       }
-      if (window.orderList.size() > 0) {
+      if (!window.orderList.isEmpty()) {
         writer.sep("ORDER BY");
         final SqlWriter.Frame orderFrame = writer.startList("", "");
         window.orderList.unparse(writer, 0, 0);
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlWithinDistinctOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlWithinDistinctOperator.java
index 3ba2df03fa..828cf3aade 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlWithinDistinctOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlWithinDistinctOperator.java
@@ -23,10 +23,10 @@ import org.apache.calcite.sql.validate.SqlValidator;
 import org.apache.calcite.sql.validate.SqlValidatorScope;
 import org.apache.calcite.sql.validate.SqlValidatorUtil;
 
-import java.util.Objects;
-
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * An operator that applies a distinct operation before rows are included in an
  * aggregate function.
@@ -69,8 +69,8 @@ public class SqlWithinDistinctOperator extends SqlBinaryOperator {
           RESOURCE.withinDistinctNotAllowed(
               flat.aggregateCall.getOperator().getName()));
     }
-    for (SqlNode order : Objects.requireNonNull(flat.distinctList)) {
-      Objects.requireNonNull(validator.deriveType(scope, order));
+    for (SqlNode order : requireNonNull(flat.distinctList)) {
+      requireNonNull(validator.deriveType(scope, order));
     }
     validator.validateAggregateParams(flat.aggregateCall, flat.filter,
         flat.distinctList, flat.orderList, scope);
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlWithinGroupOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlWithinGroupOperator.java
index c6ced0961b..8754c4d7ca 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlWithinGroupOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlWithinGroupOperator.java
@@ -25,10 +25,10 @@ import org.apache.calcite.sql.validate.SqlValidatorNamespace;
 import org.apache.calcite.sql.validate.SqlValidatorScope;
 import org.apache.calcite.sql.validate.SqlValidatorUtil;
 
-import java.util.Objects;
-
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * An operator that applies a sort operation before rows are included in an aggregate function.
  *
@@ -71,8 +71,8 @@ public class SqlWithinGroupOperator extends SqlBinaryOperator {
       throw validator.newValidationError(call, RESOURCE.withinGroupNotAllowed(operator.getName()));
     }
 
-    for (SqlNode order : Objects.requireNonNull(flat.orderList)) {
-      Objects.requireNonNull(validator.deriveType(scope, order));
+    for (SqlNode order : requireNonNull(flat.orderList)) {
+      requireNonNull(validator.deriveType(scope, order));
     }
     validator.validateAggregateParams(flat.aggregateCall, flat.filter,
         flat.distinctList, flat.orderList, scope);
diff --git a/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisor.java b/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisor.java
index 572cb8f159..c830dc2cd7 100644
--- a/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisor.java
+++ b/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisor.java
@@ -230,7 +230,7 @@ public class SqlAdvisor {
    * @return preferred casing when replacing input word
    */
   private Casing getPreferredCasing(String word) {
-    if (word == prevWord) {
+    if (word.equals(prevWord)) {
       return castNonNull(prevPreferredCasing);
     }
     boolean hasLower = false;
@@ -621,11 +621,11 @@ public class SqlAdvisor {
 
   /** Text and position info of a validator or parser exception. */
   public static class ValidateErrorInfo {
-    private int startLineNum;
-    private int startColumnNum;
-    private int endLineNum;
-    private int endColumnNum;
-    private @Nullable String errorMsg;
+    private final int startLineNum;
+    private final int startColumnNum;
+    private final int endLineNum;
+    private final int endColumnNum;
+    private final @Nullable String errorMsg;
 
     /**
      * Creates a new ValidateErrorInfo with the position coordinates and an
diff --git a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateForeignSchema.java b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateForeignSchema.java
index 4612918174..53e106b4d8 100644
--- a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateForeignSchema.java
+++ b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateForeignSchema.java
@@ -34,12 +34,13 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.AbstractList;
 import java.util.List;
-import java.util.Objects;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Parse tree for {@code CREATE FOREIGN SCHEMA} statement.
  */
@@ -58,7 +59,7 @@ public class SqlCreateForeignSchema extends SqlCreate {
       SqlIdentifier name, @Nullable SqlNode type, @Nullable SqlNode library,
       @Nullable SqlNodeList optionList) {
     super(OPERATOR, pos, replace, ifNotExists);
-    this.name = Objects.requireNonNull(name, "name");
+    this.name = requireNonNull(name, "name");
     this.type = type;
     this.library = library;
     checkArgument((type == null) != (library == null),
diff --git a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateFunction.java b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateFunction.java
index 7395187554..ae0abc2898 100644
--- a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateFunction.java
@@ -31,10 +31,11 @@ import org.apache.calcite.util.Util;
 
 import java.util.Arrays;
 import java.util.List;
-import java.util.Objects;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Parse tree for {@code CREATE FUNCTION} statement.
  */
@@ -51,9 +52,9 @@ public class SqlCreateFunction extends SqlCreate {
       boolean ifNotExists, SqlIdentifier name,
       SqlNode className, SqlNodeList usingList) {
     super(OPERATOR, pos, replace, ifNotExists);
-    this.name = Objects.requireNonNull(name, "name");
-    this.className = className;
-    this.usingList = Objects.requireNonNull(usingList, "usingList");
+    this.name = requireNonNull(name, "name");
+    this.className = requireNonNull(className, "className");
+    this.usingList = requireNonNull(usingList, "usingList");
     checkArgument(usingList.size() % 2 == 0);
   }
 
diff --git a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateMaterializedView.java b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateMaterializedView.java
index 84ddeb7cb8..a5ccd904db 100644
--- a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateMaterializedView.java
+++ b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateMaterializedView.java
@@ -30,7 +30,8 @@ import org.apache.calcite.util.ImmutableNullableList;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Parse tree for {@code CREATE MATERIALIZED VIEW} statement.
@@ -49,9 +50,9 @@ public class SqlCreateMaterializedView extends SqlCreate {
       boolean ifNotExists, SqlIdentifier name, @Nullable SqlNodeList columnList,
       SqlNode query) {
     super(OPERATOR, pos, replace, ifNotExists);
-    this.name = Objects.requireNonNull(name, "name");
+    this.name = requireNonNull(name, "name");
     this.columnList = columnList; // may be null
-    this.query = Objects.requireNonNull(query, "query");
+    this.query = requireNonNull(query, "query");
   }
 
   @SuppressWarnings("nullness")
diff --git a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateSchema.java b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateSchema.java
index 1d3c825691..ee405b0c2d 100644
--- a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateSchema.java
+++ b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateSchema.java
@@ -27,7 +27,8 @@ import org.apache.calcite.sql.parser.SqlParserPos;
 import org.apache.calcite.util.ImmutableNullableList;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Parse tree for {@code CREATE SCHEMA} statement.
@@ -42,7 +43,7 @@ public class SqlCreateSchema extends SqlCreate {
   SqlCreateSchema(SqlParserPos pos, boolean replace, boolean ifNotExists,
       SqlIdentifier name) {
     super(OPERATOR, pos, replace, ifNotExists);
-    this.name = Objects.requireNonNull(name, "name");
+    this.name = requireNonNull(name, "name");
   }
 
   @Override public List<SqlNode> getOperandList() {
diff --git a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateTable.java b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateTable.java
index 0dfb81d0fc..7e7dd144cb 100644
--- a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateTable.java
+++ b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateTable.java
@@ -30,7 +30,8 @@ import org.apache.calcite.util.ImmutableNullableList;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Parse tree for {@code CREATE TABLE} statement.
@@ -47,7 +48,7 @@ public class SqlCreateTable extends SqlCreate {
   protected SqlCreateTable(SqlParserPos pos, boolean replace, boolean ifNotExists,
       SqlIdentifier name, @Nullable SqlNodeList columnList, @Nullable SqlNode query) {
     super(OPERATOR, pos, replace, ifNotExists);
-    this.name = Objects.requireNonNull(name, "name");
+    this.name = requireNonNull(name, "name");
     this.columnList = columnList; // may be null
     this.query = query; // for "CREATE TABLE ... AS query"; may be null
   }
diff --git a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateType.java b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateType.java
index 1bbf4c3027..67188f736b 100644
--- a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateType.java
+++ b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateType.java
@@ -31,7 +31,8 @@ import org.apache.calcite.util.ImmutableNullableList;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Parse tree for {@code CREATE TYPE} statement.
@@ -48,7 +49,7 @@ public class SqlCreateType extends SqlCreate {
   SqlCreateType(SqlParserPos pos, boolean replace, SqlIdentifier name,
       @Nullable SqlNodeList attributeDefs, @Nullable SqlDataTypeSpec dataType) {
     super(OPERATOR, pos, replace, false);
-    this.name = Objects.requireNonNull(name, "name");
+    this.name = requireNonNull(name, "name");
     this.attributeDefs = attributeDefs; // may be null
     this.dataType = dataType; // may be null
   }
diff --git a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateView.java b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateView.java
index a525019e6f..662e864966 100644
--- a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateView.java
+++ b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateView.java
@@ -30,7 +30,8 @@ import org.apache.calcite.util.ImmutableNullableList;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Parse tree for {@code CREATE VIEW} statement.
@@ -47,9 +48,9 @@ public class SqlCreateView extends SqlCreate {
   SqlCreateView(SqlParserPos pos, boolean replace, SqlIdentifier name,
       @Nullable SqlNodeList columnList, SqlNode query) {
     super(OPERATOR, pos, replace, false);
-    this.name = Objects.requireNonNull(name, "name");
+    this.name = requireNonNull(name, "name");
     this.columnList = columnList; // may be null
-    this.query = Objects.requireNonNull(query, "query");
+    this.query = requireNonNull(query, "query");
   }
 
   @SuppressWarnings("nullness")
diff --git a/core/src/main/java/org/apache/calcite/sql/dialect/BigQuerySqlDialect.java b/core/src/main/java/org/apache/calcite/sql/dialect/BigQuerySqlDialect.java
index 5fa7382112..2368040cc4 100644
--- a/core/src/main/java/org/apache/calcite/sql/dialect/BigQuerySqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/dialect/BigQuerySqlDialect.java
@@ -55,6 +55,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.regex.Pattern;
 
+import static java.lang.Long.parseLong;
 import static java.util.Objects.requireNonNull;
 
 /**
@@ -229,7 +230,7 @@ public class BigQuerySqlDialect extends SqlDialect {
       writer.print("-");
     }
     try {
-      Long.parseLong(interval.getIntervalLiteral());
+      parseLong(interval.getIntervalLiteral());
     } catch (NumberFormatException e) {
       throw new RuntimeException("Only INT64 is supported as the interval value for BigQuery.");
     }
diff --git a/core/src/main/java/org/apache/calcite/sql/dialect/FireboltSqlDialect.java b/core/src/main/java/org/apache/calcite/sql/dialect/FireboltSqlDialect.java
index 4c5e4aad20..49b74d07ed 100644
--- a/core/src/main/java/org/apache/calcite/sql/dialect/FireboltSqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/dialect/FireboltSqlDialect.java
@@ -46,6 +46,8 @@ import java.util.List;
 import java.util.Locale;
 import java.util.regex.Pattern;
 
+import static java.lang.Long.parseLong;
+
 /**
  * A SqlDialect implementation for the Firebolt database.
  */
@@ -214,7 +216,7 @@ public class FireboltSqlDialect extends SqlDialect {
     writer.keyword("INTERVAL");
     writer.print("'");
     try {
-      Long.parseLong(interval.getIntervalLiteral());
+      parseLong(interval.getIntervalLiteral());
     } catch (NumberFormatException e) {
       throw new RuntimeException("Only INT64 is supported as the interval value for Firebolt.");
     }
diff --git a/core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java b/core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java
index d96b898784..4b6c7c3292 100644
--- a/core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java
@@ -161,7 +161,7 @@ public class PrestoSqlDialect extends SqlDialect {
   /**
    * change map open/close symbol from default [] to ().
    */
-  private void unparseMapValue(SqlWriter writer, SqlCall call,
+  private static void unparseMapValue(SqlWriter writer, SqlCall call,
       int leftPrec, int rightPrec) {
     call = convertMapValueCall(call);
     writer.keyword(call.getOperator().getName());
@@ -174,10 +174,11 @@ public class PrestoSqlDialect extends SqlDialect {
   }
 
   /**
-   * Convert Presto MapValue call
-   * From MAP['k1','v1','k2','v2'] to MAP[ARRAY['k1', 'k2'],ARRAY['v1', 'v2']].
+   * Converts a Presto MapValue call
+   * from {@code MAP['k1', 'v1', 'k2', 'v2']}
+   * to {@code MAP[ARRAY['k1', 'k2'], ARRAY['v1', 'v2']]}.
    */
-  private SqlCall convertMapValueCall(SqlCall call) {
+  private static SqlCall convertMapValueCall(SqlCall call) {
     boolean unnestMap = call.operandCount() > 0
         && call.getOperandList().stream().allMatch(operand -> operand instanceof SqlLiteral);
     if (!unnestMap) {
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlAbstractGroupFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlAbstractGroupFunction.java
index 8c5c4712de..a4aa00477c 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlAbstractGroupFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlAbstractGroupFunction.java
@@ -36,6 +36,8 @@ import org.apache.calcite.util.Static;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Base class for grouping functions {@code GROUP_ID}, {@code GROUPING_ID},
  * {@code GROUPING}.
@@ -65,8 +67,7 @@ public class SqlAbstractGroupFunction extends SqlAggFunction {
       SqlValidatorScope scope, SqlValidatorScope operandScope) {
     super.validateCall(call, validator, scope, operandScope);
     final SelectScope selectScope =
-        SqlValidatorUtil.getEnclosingSelectScope(scope);
-    assert selectScope != null;
+        requireNonNull(SqlValidatorUtil.getEnclosingSelectScope(scope));
     final SqlSelect select = selectScope.getNode();
     if (!validator.isAggregate(select)) {
       throw validator.newValidationError(call,
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlBasicAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlBasicAggFunction.java
index b63b37cf29..76b7e4de44 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlBasicAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlBasicAggFunction.java
@@ -69,7 +69,8 @@ public final class SqlBasicAggFunction extends SqlAggFunction {
       SqlSyntax syntax, boolean allowsNullTreatment, boolean allowsSeparator,
       boolean percentile, boolean allowsFraming) {
     super(name, sqlIdentifier, kind,
-        requireNonNull(returnTypeInference, "returnTypeInference"), operandTypeInference,
+        requireNonNull(returnTypeInference, "returnTypeInference"),
+        operandTypeInference,
         requireNonNull(operandTypeChecker, "operandTypeChecker"),
         requireNonNull(funcType, "funcType"), requiresOrder, requiresOver,
         requiresGroupOrder);
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlDotOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlDotOperator.java
index 2bc78ae380..3d3896f76e 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlDotOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlDotOperator.java
@@ -100,8 +100,7 @@ public class SqlDotOperator extends SqlSpecialOperator {
       SqlValidatorScope scope, SqlCall call) {
     final SqlNode operand = call.getOperandList().get(0);
     final RelDataType nodeType =
-        validator.deriveType(scope, operand);
-    assert nodeType != null;
+        requireNonNull(validator.deriveType(scope, operand));
     if (!nodeType.isStruct()) {
       throw SqlUtil.newContextException(operand.getParserPosition(),
           Static.RESOURCE.incompatibleTypes());
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlExtractFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlExtractFunction.java
index 8d2c4eedf4..9c8d4b36e2 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlExtractFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlExtractFunction.java
@@ -37,11 +37,11 @@ import org.apache.calcite.util.Util;
 
 import com.google.common.collect.ImmutableSet;
 
-import java.util.Objects;
-
 import static org.apache.calcite.sql.validate.SqlNonNullableAccessors.getOperandLiteralValueOrThrow;
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * The SQL <code>EXTRACT</code> operator. Extracts a specified field value from
  * a DATETIME or an INTERVAL. E.g.<br>
@@ -152,9 +152,7 @@ public class SqlExtractFunction extends SqlFunction {
     if (call.operand(0) instanceof SqlCharStringLiteral) {
       final SqlCharStringLiteral stringLiteral = call.operand(0);
       qualifier =
-          new SqlIntervalQualifier(
-              Objects.requireNonNull(
-                  stringLiteral.toValue()),
+          new SqlIntervalQualifier(requireNonNull(stringLiteral.toValue()),
               call.operand(0).getParserPosition());
     } else {
       qualifier = call.operand(0);
@@ -225,7 +223,7 @@ public class SqlExtractFunction extends SqlFunction {
       value =
           TimeUnitRange.of(
               SqlIntervalQualifier.stringToDatePartTimeUnit(
-              Objects.requireNonNull(call.getOperandLiteralValue(0, String.class))),
+                  requireNonNull(call.getOperandLiteralValue(0, String.class))),
           null);
     } else {
       value = getOperandLiteralValueOrThrow(call, 0, TimeUnitRange.class);
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonArrayAggAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonArrayAggAggFunction.java
index f90e882834..cce6f38ff2 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonArrayAggAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonArrayAggAggFunction.java
@@ -36,7 +36,7 @@ import org.apache.calcite.util.Optionality;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
 
-import java.util.Objects;
+import static java.util.Objects.requireNonNull;
 
 /**
  * The <code>JSON_OBJECTAGG</code> aggregate function.
@@ -49,7 +49,7 @@ public class SqlJsonArrayAggAggFunction extends SqlAggFunction {
     super(kind + "_" + nullClause.name(), null, kind, ReturnTypes.VARCHAR_2000,
         InferTypes.ANY_NULLABLE, OperandTypes.family(SqlTypeFamily.ANY),
         SqlFunctionCategory.SYSTEM, false, false, Optionality.OPTIONAL);
-    this.nullClause = Objects.requireNonNull(nullClause, "nullClause");
+    this.nullClause = requireNonNull(nullClause, "nullClause");
   }
 
   @Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec,
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonObjectAggAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonObjectAggAggFunction.java
index aae4c7fdaa..aab6d0dbd4 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonObjectAggAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonObjectAggAggFunction.java
@@ -33,7 +33,7 @@ import org.apache.calcite.sql.validate.SqlValidator;
 import org.apache.calcite.sql.validate.SqlValidatorScope;
 import org.apache.calcite.util.Optionality;
 
-import java.util.Objects;
+import static java.util.Objects.requireNonNull;
 
 /**
  * The <code>JSON_OBJECTAGG</code> aggregate function.
@@ -54,7 +54,7 @@ public class SqlJsonObjectAggAggFunction extends SqlAggFunction {
         },
         OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.ANY),
         SqlFunctionCategory.SYSTEM, false, false, Optionality.FORBIDDEN);
-    this.nullClause = Objects.requireNonNull(nullClause, "nullClause");
+    this.nullClause = requireNonNull(nullClause, "nullClause");
   }
 
   @Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec,
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonQueryFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonQueryFunction.java
index 31f2329735..fcb0e69a3a 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonQueryFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonQueryFunction.java
@@ -43,7 +43,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 import java.util.Optional;
 
 import static java.util.Objects.requireNonNull;
@@ -77,7 +76,7 @@ public class SqlJsonQueryFunction extends SqlFunction {
 
   private static RelDataType deriveExplicitType(SqlOperatorBinding opBinding, RelDataType type) {
     if (SqlTypeName.ARRAY == type.getSqlTypeName()) {
-      RelDataType elementType = Objects.requireNonNull(type.getComponentType());
+      RelDataType elementType = requireNonNull(type.getComponentType());
       RelDataType nullableElementType = deriveExplicitType(opBinding, elementType);
       return SqlTypeUtil.createArrayType(
           opBinding.getTypeFactory(),
@@ -131,8 +130,8 @@ public class SqlJsonQueryFunction extends SqlFunction {
   @Override public SqlCall createCall(@Nullable SqlLiteral functionQualifier,
       SqlParserPos pos, @Nullable SqlNode... operands) {
     final List<SqlNode> args = new ArrayList<>();
-    args.add(Objects.requireNonNull(operands[0]));
-    args.add(Objects.requireNonNull(operands[1]));
+    args.add(requireNonNull(operands[0]));
+    args.add(requireNonNull(operands[1]));
 
     if (operands[2] == null) {
       args.add(SqlLiteral.createSymbol(SqlJsonQueryWrapperBehavior.WITHOUT_ARRAY, pos));
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonValueFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonValueFunction.java
index 84bc1bad68..005b4f4613 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonValueFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonValueFunction.java
@@ -46,6 +46,8 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.stream.Collectors;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * The <code>JSON_VALUE</code> function.
  */
@@ -65,7 +67,7 @@ public class SqlJsonValueFunction extends SqlFunction {
 
   private static RelDataType deriveExplicitType(SqlOperatorBinding opBinding, RelDataType type) {
     if (SqlTypeName.ARRAY == type.getSqlTypeName()) {
-      RelDataType elementType = Objects.requireNonNull(type.getComponentType());
+      RelDataType elementType = requireNonNull(type.getComponentType());
       RelDataType nullableElementType = deriveExplicitType(opBinding, elementType);
       return SqlTypeUtil.createArrayType(
           opBinding.getTypeFactory(),
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlLiteralChainOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlLiteralChainOperator.java
index 9e23989087..259df4cbdc 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLiteralChainOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLiteralChainOperator.java
@@ -196,7 +196,7 @@ public class SqlLiteralChainOperator extends SqlSpecialOperator {
    */
   public static SqlLiteral concatenateOperands(SqlCall call) {
     final List<SqlNode> operandList = call.getOperandList();
-    assert operandList.size() > 0;
+    assert !operandList.isEmpty();
     assert operandList.get(0) instanceof SqlLiteral
         : operandList.get(0).getClass();
     return SqlUtil.concatenateLiterals(
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlMapValueConstructor.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlMapValueConstructor.java
index a497471200..e7c0132472 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlMapValueConstructor.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlMapValueConstructor.java
@@ -66,7 +66,7 @@ public class SqlMapValueConstructor extends SqlMultisetValueConstructor {
       SqlCallBinding callBinding,
       boolean throwOnFailure) {
     final List<RelDataType> argTypes = SqlTypeUtil.deriveType(callBinding, callBinding.operands());
-    if (argTypes.size() == 0) {
+    if (argTypes.isEmpty()) {
       throw callBinding.newValidationError(RESOURCE.mapRequiresTwoOrMoreArgs());
     }
     if (argTypes.size() % 2 > 0) {
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlMultisetValueConstructor.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlMultisetValueConstructor.java
index acbafc97e0..99ee65736f 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlMultisetValueConstructor.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlMultisetValueConstructor.java
@@ -96,7 +96,7 @@ public class SqlMultisetValueConstructor extends SqlSpecialOperator {
       boolean throwOnFailure) {
     final List<RelDataType> argTypes =
         SqlTypeUtil.deriveType(callBinding, callBinding.operands());
-    if (argTypes.size() == 0) {
+    if (argTypes.isEmpty()) {
       throw callBinding.newValidationError(RESOURCE.requireAtLeastOneArg());
     }
     final RelDataType componentType =
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlQuantifyOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlQuantifyOperator.java
index 1ba3f599c4..c8409377a6 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlQuantifyOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlQuantifyOperator.java
@@ -29,10 +29,11 @@ import org.apache.calcite.sql.validate.SqlValidatorScope;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.List;
-import java.util.Objects;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Definition of the SQL <code>ALL</code> and <code>SOME</code>operators.
  *
@@ -60,7 +61,7 @@ public class SqlQuantifyOperator extends SqlInOperator {
    */
   SqlQuantifyOperator(SqlKind kind, SqlKind comparisonKind) {
     super(comparisonKind.sql + " " + kind, kind);
-    this.comparisonKind = Objects.requireNonNull(comparisonKind, "comparisonKind");
+    this.comparisonKind = requireNonNull(comparisonKind, "comparisonKind");
     checkArgument(comparisonKind == SqlKind.EQUALS
         || comparisonKind == SqlKind.NOT_EQUALS
         || comparisonKind == SqlKind.LESS_THAN_OR_EQUAL
@@ -98,15 +99,20 @@ public class SqlQuantifyOperator extends SqlInOperator {
     final SqlNode left = call.operand(0);
     final SqlNode right = call.operand(1);
     if (right instanceof SqlNodeList && ((SqlNodeList) right).size() == 1) {
-      final RelDataType rightType = validator.deriveType(scope, ((SqlNodeList) right).get(0));
+      final RelDataType rightType =
+          validator.deriveType(scope, ((SqlNodeList) right).get(0));
       if (SqlTypeUtil.isCollection(rightType)) {
-        final RelDataType componentRightType = Objects.requireNonNull(rightType.getComponentType());
+        final RelDataType componentRightType =
+            requireNonNull(rightType.getComponentType());
         final RelDataType leftType = validator.deriveType(scope, left);
         if (SqlTypeUtil.sameNamedType(componentRightType, leftType)
-            || SqlTypeUtil.isNull(leftType) || SqlTypeUtil.isNull(componentRightType)) {
+            || SqlTypeUtil.isNull(leftType)
+            || SqlTypeUtil.isNull(componentRightType)) {
           return validator.getTypeFactory().createTypeWithNullability(
               validator.getTypeFactory().createSqlType(SqlTypeName.BOOLEAN),
-              rightType.isNullable() || componentRightType.isNullable() || leftType.isNullable());
+              rightType.isNullable()
+                  || componentRightType.isNullable()
+                  || leftType.isNullable());
         }
       }
     }
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlRollupOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlRollupOperator.java
index ed0007bcd7..19fee54bd6 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlRollupOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlRollupOperator.java
@@ -90,7 +90,7 @@ class SqlRollupOperator extends SqlInternalOperator {
         }
         writer.endList(frame2);
       } else if (operand instanceof SqlNodeList
-          && ((SqlNodeList) operand).size() == 0) {
+          && ((SqlNodeList) operand).isEmpty()) {
         writer.keyword("()");
       } else {
         operand.unparse(writer, 0, 0);
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlSpatialTypeFunctions.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlSpatialTypeFunctions.java
index 7963948551..296ca3de0d 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlSpatialTypeFunctions.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlSpatialTypeFunctions.java
@@ -125,7 +125,7 @@ public class SqlSpatialTypeFunctions {
     private final Geometry geom;
     private final BigDecimal deltaX;
     private final BigDecimal deltaY;
-    private boolean point;
+    private final boolean point;
 
     GridTable(Geometry geom, BigDecimal deltaX, BigDecimal deltaY,
         boolean point) {
diff --git a/core/src/main/java/org/apache/calcite/sql/parser/SqlParserPos.java b/core/src/main/java/org/apache/calcite/sql/parser/SqlParserPos.java
index 97c6b88bd1..53e62346a3 100644
--- a/core/src/main/java/org/apache/calcite/sql/parser/SqlParserPos.java
+++ b/core/src/main/java/org/apache/calcite/sql/parser/SqlParserPos.java
@@ -206,7 +206,7 @@ public class SqlParserPos implements Serializable {
    * which spans from the beginning of the first to the end of the last.
    */
   public static SqlParserPos sum(final List<? extends SqlNode> nodes) {
-    if (nodes.size() == 0) {
+    if (nodes.isEmpty()) {
       throw new AssertionError();
     }
     SqlParserPos pos0 = nodes.get(0).getParserPosition();
@@ -228,7 +228,7 @@ public class SqlParserPos implements Serializable {
         poses instanceof List
             ? (List<SqlParserPos>) poses
             : Lists.newArrayList(poses);
-    if (list.size() == 0) {
+    if (list.isEmpty()) {
       throw new AssertionError();
     }
     final SqlParserPos pos0 = list.get(0);
diff --git a/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
index db9b38afad..2269ecec49 100644
--- a/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
+++ b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
@@ -268,7 +268,7 @@ public class SqlPrettyWriter implements SqlWriter {
   private static final Bean DEFAULT_BEAN =
       new SqlPrettyWriter(SqlPrettyWriter.config()
           .withDialect(AnsiSqlDialect.DEFAULT)).getBean();
-  protected static final String NL = System.getProperty("line.separator");
+  protected static final String NL = System.lineSeparator();
 
   //~ Instance fields --------------------------------------------------------
 
@@ -299,9 +299,8 @@ public class SqlPrettyWriter implements SqlWriter {
 
   /** Creates a writer with the given configuration
    * and a given buffer to write to. */
-  public SqlPrettyWriter(SqlWriterConfig config,
-      StringBuilder buf) {
-    this(config, requireNonNull(buf, "buf"), false);
+  public SqlPrettyWriter(SqlWriterConfig config, StringBuilder buf) {
+    this(config, buf, false);
   }
 
   /** Creates a writer with the given configuration and dialect,
@@ -855,7 +854,7 @@ public class SqlPrettyWriter implements SqlWriter {
       @Nullable String keyword,
       String open,
       String close) {
-    assert frameType != null;
+    requireNonNull(frameType, "frameType");
     FrameImpl frame = this.frame;
     if (frame != null) {
       if (frame.itemCount++ == 0 && frame.newlineAfterOpen) {
@@ -942,7 +941,7 @@ public class SqlPrettyWriter implements SqlWriter {
         isKeywordsLowerCase()
             ? s.toLowerCase(Locale.ROOT)
             : s.toUpperCase(Locale.ROOT));
-    if (!s.equals("")) {
+    if (!s.isEmpty()) {
       setNeedWhitespace(needWhitespaceAfter(s));
     }
   }
@@ -959,7 +958,7 @@ public class SqlPrettyWriter implements SqlWriter {
         || s.equals(")")
         || s.equals("[")
         || s.equals("]")
-        || s.equals(""));
+        || s.isEmpty());
   }
 
   private static boolean needWhitespaceAfter(String s) {
@@ -1058,13 +1057,12 @@ public class SqlPrettyWriter implements SqlWriter {
   }
 
   @Override public Frame startList(FrameTypeEnum frameType) {
-    assert frameType != null;
-    return startList(frameType, null, "", "");
+    return startList(requireNonNull(frameType, "frameType"), null, "", "");
   }
 
-  @Override public Frame startList(FrameType frameType, String open, String close) {
-    assert frameType != null;
-    return startList(frameType, null, open, close);
+  @Override public Frame startList(FrameType frameType, String open,
+      String close) {
+    return startList(requireNonNull(frameType, "frameType"), null, open, close);
   }
 
   @Override public SqlWriter list(FrameTypeEnum frameType, Consumer<SqlWriter> action) {
@@ -1181,12 +1179,12 @@ public class SqlPrettyWriter implements SqlWriter {
         boolean newlineBeforeClose, boolean newlineAfterClose) {
       this.frameType = frameType;
       this.keyword = keyword;
-      this.open = open;
-      this.close = close;
+      this.open = requireNonNull(open, "open");
+      this.close = requireNonNull(close, "close");
       this.left = left;
       this.extraIndent = extraIndent;
       this.chopLimit = chopLimit;
-      this.lineFolding = lineFolding;
+      this.lineFolding = requireNonNull(lineFolding, "lineFolding");
       this.newlineAfterOpen = newlineAfterOpen;
       this.newlineBeforeSep = newlineBeforeSep;
       this.newlineAfterSep = newlineAfterSep;
@@ -1200,7 +1198,7 @@ public class SqlPrettyWriter implements SqlWriter {
     }
 
     protected void before() {
-      if ((open != null) && !open.equals("")) {
+      if (!open.isEmpty()) {
         keyword(open);
       }
     }
@@ -1299,14 +1297,12 @@ public class SqlPrettyWriter implements SqlWriter {
       final int lprec = sepOp.getRightPrec();
       final int rprec = sepOp.getLeftPrec();
       if (chopLimit < 0) {
-        for (int i = 0; i < list.size(); i++) {
-          SqlNode node = list.get(i);
+        for (SqlNode node : list) {
           sep(false, sepOp.getName());
           node.unparse(SqlPrettyWriter.this, lprec, rprec);
         }
       } else if (newlineBeforeSep) {
-        for (int i = 0; i < list.size(); i++) {
-          SqlNode node = list.get(i);
+        for (SqlNode node : list) {
           sep(false, sepOp.getName());
           final Save prevSize = new Save();
           node.unparse(SqlPrettyWriter.this, lprec, rprec);
diff --git a/core/src/main/java/org/apache/calcite/sql/type/AbstractSqlType.java b/core/src/main/java/org/apache/calcite/sql/type/AbstractSqlType.java
index 2e059e1e16..16962b0856 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/AbstractSqlType.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/AbstractSqlType.java
@@ -26,7 +26,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.io.Serializable;
 import java.util.List;
-import java.util.Objects;
+
+import static java.util.Objects.requireNonNull;
 
 /**
  * Abstract base class for SQL implementations of {@link RelDataType}.
@@ -37,7 +38,7 @@ public abstract class AbstractSqlType
   //~ Instance fields --------------------------------------------------------
 
   protected final SqlTypeName typeName;
-  protected boolean isNullable;
+  protected final boolean isNullable;
 
   //~ Constructors -----------------------------------------------------------
 
@@ -53,7 +54,7 @@ public abstract class AbstractSqlType
       boolean isNullable,
       @Nullable List<? extends RelDataTypeField> fields) {
     super(fields);
-    this.typeName = Objects.requireNonNull(typeName, "typeName");
+    this.typeName = requireNonNull(typeName, "typeName");
     this.isNullable = isNullable || (typeName == SqlTypeName.NULL);
   }
 
diff --git a/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java b/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java
index 847e596286..9441303dad 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java
@@ -23,10 +23,11 @@ import org.apache.calcite.util.SerializableCharset;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.nio.charset.Charset;
-import java.util.Objects;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * BasicSqlType represents a standard atomic SQL type (excluding interval
  * types).
@@ -102,7 +103,7 @@ public class BasicSqlType extends AbstractSqlType {
       @Nullable SqlCollation collation,
       @Nullable SerializableCharset wrappedCharset) {
     super(typeName, nullable, null);
-    this.typeSystem = Objects.requireNonNull(typeSystem, "typeSystem");
... 17563 lines suppressed ...