Skip to content

Commit

Permalink
[CALCITE-4431] Use requireNonNull(var, "var") instead of requireNonNu…
Browse files Browse the repository at this point in the history
…ll(var) for better error messages

This makes it easier to understand the reason for the failure, especially
when multiple requireNonNull lines go side-by-side.

The added AutoStyle configuration ensures the label does not go out-of-sync
  • Loading branch information
vlsi committed Jan 25, 2021
1 parent 6dace36 commit 12a484a
Show file tree
Hide file tree
Showing 216 changed files with 557 additions and 556 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ allprojects {
replaceRegex("@Override should not be on its own line", "(@Override)\\s{2,}", "\$1 ")
replaceRegex("@Test should not be on its own line", "(@Test)\\s{2,}", "\$1 ")
replaceRegex("Newline in string should be at end of line", """\\n" *\+""", "\\n\"\n +")
replaceRegex("require message for requireNonNull", """(?<!#)requireNonNull\(\s*(\w+)\s*(?:,\s*"(?!\1")\w+"\s*)?\)""", "requireNonNull($1, \"$1\")")
// (?-m) disables multiline, so $ matches the very end of the file rather than end of line
replaceRegex("Remove '// End file.java' trailer", "(?-m)\n// End [^\n]+\\.\\w+\\s*$", "")
replaceRegex("<p> should not be placed a the end of the line", "(?-m)\\s*+<p> *+\n \\* ", "\n *\n * <p>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ private RexToLixTranslator(@Nullable RexProgram program,
SqlConformance conformance,
@Nullable Function1<String, InputGetter> correlates) {
this.program = program; // may be null
this.typeFactory = requireNonNull(typeFactory);
this.conformance = requireNonNull(conformance);
this.root = requireNonNull(root);
this.typeFactory = requireNonNull(typeFactory, "typeFactory");
this.conformance = requireNonNull(conformance, "conformance");
this.root = requireNonNull(root, "root");
this.inputGetter = inputGetter;
this.list = requireNonNull(list);
this.builder = requireNonNull(builder);
this.list = requireNonNull(list, "list");
this.builder = requireNonNull(builder, "builder");
this.correlates = correlates; // may be null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public class JdbcCatalogSchema extends AbstractSchema {
/** Creates a JdbcCatalogSchema. */
public JdbcCatalogSchema(DataSource dataSource, SqlDialect dialect,
JdbcConvention convention, String catalog) {
this.dataSource = requireNonNull(dataSource);
this.dialect = requireNonNull(dialect);
this.convention = requireNonNull(convention);
this.dataSource = requireNonNull(dataSource, "dataSource");
this.dialect = requireNonNull(dialect, "dialect");
this.convention = requireNonNull(convention, "convention");
this.catalog = catalog;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public class JdbcTable extends AbstractQueryableTable
String jdbcSchemaName, String jdbcTableName,
Schema.TableType jdbcTableType) {
super(Object[].class);
this.jdbcSchema = requireNonNull(jdbcSchema);
this.jdbcSchema = requireNonNull(jdbcSchema, "jdbcSchema");
this.jdbcCatalogName = jdbcCatalogName;
this.jdbcSchemaName = jdbcSchemaName;
this.jdbcTableName = requireNonNull(jdbcTableName);
this.jdbcTableType = requireNonNull(jdbcTableType);
this.jdbcTableName = requireNonNull(jdbcTableName, "jdbcTableName");
this.jdbcTableType = requireNonNull(jdbcTableType, "jdbcTableType");
}

@Override public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected JdbcTableScan(
JdbcTable jdbcTable,
JdbcConvention jdbcConvention) {
super(cluster, cluster.traitSetOf(jdbcConvention), ImmutableList.of(), table);
this.jdbcTable = Objects.requireNonNull(jdbcTable);
this.jdbcTable = Objects.requireNonNull(jdbcTable, "jdbcTable");
}

@Override public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/apache/calcite/config/Lex.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public enum Lex {
Casing quotedCasing,
boolean caseSensitive,
CharLiteralStyle... charLiteralStyles) {
this.quoting = Objects.requireNonNull(quoting);
this.unquotedCasing = Objects.requireNonNull(unquotedCasing);
this.quotedCasing = Objects.requireNonNull(quotedCasing);
this.quoting = Objects.requireNonNull(quoting, "quoting");
this.unquotedCasing = Objects.requireNonNull(unquotedCasing, "unquotedCasing");
this.quotedCasing = Objects.requireNonNull(quotedCasing, "quotedCasing");
this.caseSensitive = caseSensitive;
this.charLiteralStyles = ImmutableSet.copyOf(charLiteralStyles);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ public static class BindableTableScan
RelOptTable table, ImmutableList<RexNode> filters,
ImmutableIntList projects) {
super(cluster, traitSet, ImmutableList.of(), table);
this.filters = Objects.requireNonNull(filters);
this.projects = Objects.requireNonNull(projects);
this.filters = Objects.requireNonNull(filters, "filters");
this.projects = Objects.requireNonNull(projects, "projects");
Preconditions.checkArgument(canHandle(table));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class Interpreter extends AbstractEnumerable<@Nullable Object[]>

/** Creates an Interpreter. */
public Interpreter(DataContext dataContext, RelNode rootRel) {
this.dataContext = requireNonNull(dataContext);
this.dataContext = requireNonNull(dataContext, "dataContext");
final RelNode rel = optimize(rootRel);
final CompilerImpl compiler =
new Nodes.CoreCompiler(this, rootRel.getCluster());
Expand Down Expand Up @@ -280,7 +280,7 @@ private static class EnumeratorSource implements Source {
private final Enumerator<Row> enumerator;

EnumeratorSource(final Enumerator<Row> enumerator) {
this.enumerator = requireNonNull(enumerator);
this.enumerator = requireNonNull(enumerator, "enumerator");
}

@Override public @Nullable Row receive() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ static class ContextImpl implements CalcitePrepare.Context {
private final CalciteSchema rootSchema;

ContextImpl(CalciteConnectionImpl connection) {
this.connection = requireNonNull(connection);
this.connection = requireNonNull(connection, "connection");
long now = System.currentTimeMillis();
SchemaVersion schemaVersion = new LongSchemaVersion(now);
this.mutableRootSchema = connection.rootSchema;
Expand Down Expand Up @@ -601,7 +601,7 @@ static class CalciteServerStatementImpl
private final AtomicBoolean cancelFlag = new AtomicBoolean();

CalciteServerStatementImpl(CalciteConnectionImpl connection) {
this.connection = requireNonNull(connection);
this.connection = requireNonNull(connection, "connection");
}

@Override public Context createPrepareContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static Pattern likeToRegex(Pat pattern) {

private <E> MetaResultSet createResultSet(Enumerable<E> enumerable,
Class clazz, String... names) {
requireNonNull(names);
requireNonNull(names, "names");
final List<ColumnMetaData> columns = new ArrayList<>(names.length);
final List<Field> fields = new ArrayList<>(names.length);
final List<String> fieldNames = new ArrayList<>(names.length);
Expand Down Expand Up @@ -752,7 +752,7 @@ private static class CalciteMetaTable extends MetaTable {
String tableSchem, String tableName) {
super(tableCat, tableSchem, tableName,
calciteTable.getJdbcTableType().jdbcName);
this.calciteTable = requireNonNull(calciteTable);
this.calciteTable = requireNonNull(calciteTable, "calciteTable");
}
}

Expand Down
22 changes: 11 additions & 11 deletions core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ protected CalciteSchema(@Nullable CalciteSchema parent, Schema schema,
if (tableMap == null) {
this.tableMap = new NameMap<>();
} else {
this.tableMap = Objects.requireNonNull(tableMap);
this.tableMap = Objects.requireNonNull(tableMap, "tableMap");
}
if (latticeMap == null) {
this.latticeMap = new NameMap<>();
} else {
this.latticeMap = Objects.requireNonNull(latticeMap);
this.latticeMap = Objects.requireNonNull(latticeMap, "latticeMap");
}
if (subSchemaMap == null) {
this.subSchemaMap = new NameMap<>();
} else {
this.subSchemaMap = Objects.requireNonNull(subSchemaMap);
this.subSchemaMap = Objects.requireNonNull(subSchemaMap, "subSchemaMap");
}
if (functionMap == null) {
this.functionMap = new NameMultimap<>();
Expand All @@ -109,14 +109,14 @@ protected CalciteSchema(@Nullable CalciteSchema parent, Schema schema,
} else {
// If you specify functionMap, you must also specify functionNames and
// nullaryFunctionMap.
this.functionMap = Objects.requireNonNull(functionMap);
this.functionNames = Objects.requireNonNull(functionNames);
this.nullaryFunctionMap = Objects.requireNonNull(nullaryFunctionMap);
this.functionMap = Objects.requireNonNull(functionMap, "functionMap");
this.functionNames = Objects.requireNonNull(functionNames, "functionNames");
this.nullaryFunctionMap = Objects.requireNonNull(nullaryFunctionMap, "nullaryFunctionMap");
}
if (typeMap == null) {
this.typeMap = new NameMap<>();
} else {
this.typeMap = Objects.requireNonNull(typeMap);
this.typeMap = Objects.requireNonNull(typeMap, "typeMap");
}
this.path = path;
}
Expand Down Expand Up @@ -568,8 +568,8 @@ public abstract static class Entry {
public final String name;

protected Entry(CalciteSchema schema, String name) {
this.schema = Objects.requireNonNull(schema);
this.name = Objects.requireNonNull(name);
this.schema = Objects.requireNonNull(schema, "schema");
this.name = Objects.requireNonNull(name, "name");
}

/** Returns this object's path. For example ["hr", "emps"]. */
Expand All @@ -585,7 +585,7 @@ public abstract static class TableEntry extends Entry {
protected TableEntry(CalciteSchema schema, String name,
ImmutableList<String> sqls) {
super(schema, name);
this.sqls = Objects.requireNonNull(sqls);
this.sqls = Objects.requireNonNull(sqls, "sqls");
}

public abstract Table getTable();
Expand Down Expand Up @@ -754,7 +754,7 @@ public static class TableEntryImpl extends TableEntry {
public TableEntryImpl(CalciteSchema schema, String name, Table table,
ImmutableList<String> sqls) {
super(schema, name, sqls);
this.table = Objects.requireNonNull(table);
this.table = Objects.requireNonNull(table, "table");
}

@Override public Table getTable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class JavaRecordType extends RelRecordType {

public JavaRecordType(List<RelDataTypeField> fields, Class clazz) {
super(fields);
this.clazz = Objects.requireNonNull(clazz);
this.clazz = Objects.requireNonNull(clazz, "clazz");
}

@Override public boolean equals(@Nullable Object obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ private static class RecordFieldImpl implements Types.RecordField {
Type type,
boolean nullable,
int modifiers) {
this.syntheticType = requireNonNull(syntheticType);
this.name = requireNonNull(name);
this.type = requireNonNull(type);
this.syntheticType = requireNonNull(syntheticType, "syntheticType");
this.name = requireNonNull(name, "name");
this.type = requireNonNull(type, "type");
this.nullable = nullable;
this.modifiers = modifiers;
assert !(nullable && Primitive.is(type))
Expand Down
18 changes: 9 additions & 9 deletions core/src/main/java/org/apache/calcite/materialize/Lattice.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ private Lattice(CalciteSchema rootSchema, LatticeRootNode rootNode,
ImmutableSortedSet<Measure> defaultMeasures, ImmutableList<Tile> tiles,
ImmutableListMultimap<Integer, Boolean> columnUses) {
this.rootSchema = rootSchema;
this.rootNode = requireNonNull(rootNode);
this.columns = requireNonNull(columns);
this.rootNode = requireNonNull(rootNode, "rootNode");
this.columns = requireNonNull(columns, "columns");
this.auto = auto;
this.algorithm = algorithm;
this.algorithmMaxMillis = algorithmMaxMillis;
this.defaultMeasures = defaultMeasures.asList(); // unique and sorted
this.tiles = requireNonNull(tiles);
this.tiles = requireNonNull(tiles, "tiles");
this.columnUses = columnUses;

assert isValid(Litmus.THROW);
Expand Down Expand Up @@ -560,7 +560,7 @@ public static class Measure implements Comparable<Measure> {

public Measure(SqlAggFunction agg, boolean distinct, @Nullable String name,
Iterable<Column> args) {
this.agg = requireNonNull(agg);
this.agg = requireNonNull(agg, "agg");
this.distinct = distinct;
this.name = name;
this.args = ImmutableList.copyOf(args);
Expand Down Expand Up @@ -656,7 +656,7 @@ public abstract static class Column implements Comparable<Column> {

private Column(int ordinal, String alias) {
this.ordinal = ordinal;
this.alias = requireNonNull(alias);
this.alias = requireNonNull(alias, "alias");
}

/** Converts a list of columns to a bit set of their ordinals. */
Expand Down Expand Up @@ -701,8 +701,8 @@ public static class BaseColumn extends Column {

private BaseColumn(int ordinal, String table, String column, String alias) {
super(ordinal, alias);
this.table = requireNonNull(table);
this.column = requireNonNull(column);
this.table = requireNonNull(table, "table");
this.column = requireNonNull(column, "column");
}

@Override public String toString() {
Expand Down Expand Up @@ -1147,8 +1147,8 @@ public static class Tile {

public Tile(ImmutableList<Measure> measures,
ImmutableList<Column> dimensions) {
this.measures = requireNonNull(measures);
this.dimensions = requireNonNull(dimensions);
this.measures = requireNonNull(measures, "measures");
this.dimensions = requireNonNull(dimensions, "dimensions");
assert Ordering.natural().isStrictlyOrdered(dimensions);
assert Ordering.natural().isStrictlyOrdered(measures);
bitSet = Column.toBitSet(dimensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class LatticeSpace {
final Map<LatticeTable, List<RexNode>> tableExpressions = new HashMap<>();

LatticeSpace(SqlStatisticProvider statisticProvider) {
this.statisticProvider = Objects.requireNonNull(statisticProvider);
this.statisticProvider = Objects.requireNonNull(statisticProvider, "statisticProvider");
}

/** Derives a unique name for a table, qualifying with schema name only if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ private static class TableRef {
private final int ordinalInQuery;

private TableRef(LatticeTable table, int ordinalInQuery) {
this.table = requireNonNull(table);
this.table = requireNonNull(table, "table");
this.ordinalInQuery = ordinalInQuery;
}

Expand All @@ -659,7 +659,7 @@ private static class StepRef extends DefaultEdge {

StepRef(TableRef source, TableRef target, Step step, int ordinalInQuery) {
super(source, target);
this.step = requireNonNull(step);
this.step = requireNonNull(step, "step");
this.ordinalInQuery = ordinalInQuery;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class LatticeTable {
public final String alias;

LatticeTable(RelOptTable table) {
t = Objects.requireNonNull(table);
t = Objects.requireNonNull(table, "table");
alias = Objects.requireNonNull(Util.last(table.getQualifiedName()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static class Materialization {
RelDataType rowType,
@Nullable List<String> viewSchemaPath) {
this.key = key;
this.rootSchema = Objects.requireNonNull(rootSchema);
this.rootSchema = Objects.requireNonNull(rootSchema, "rootSchema");
Preconditions.checkArgument(rootSchema.isRoot(), "must be root schema");
this.materializedTable = materializedTable; // may be null
this.sql = sql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ 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);
this.table = Objects.requireNonNull(table, "table");
this.parent = parent;
this.step = step;
if (parent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ProfilerLatticeStatisticProvider implements LatticeStatisticProvider {

/** Creates a ProfilerLatticeStatisticProvider. */
private ProfilerLatticeStatisticProvider(Lattice lattice) {
Objects.requireNonNull(lattice);
Objects.requireNonNull(lattice, "lattice");
this.profile = Suppliers.memoize(() -> {
final ProfilerImpl profiler =
ProfilerImpl.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SqlLatticeStatisticProvider implements LatticeStatisticProvider {

/** Creates a SqlLatticeStatisticProvider. */
private SqlLatticeStatisticProvider(Lattice lattice) {
this.lattice = requireNonNull(lattice);
this.lattice = requireNonNull(lattice, "lattice");
}

@Override public double cardinality(List<Lattice.Column> columns) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/apache/calcite/materialize/Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private Step(LatticeTable source, LatticeTable target,
List<IntPair> keys, String keyString) {
super(source, target);
this.keys = ImmutableList.copyOf(keys);
this.keyString = Objects.requireNonNull(keyString);
this.keyString = Objects.requireNonNull(keyString, "keyString");
assert IntPair.ORDERING.isStrictlyOrdered(keys); // ordered and unique
}

Expand Down Expand Up @@ -147,7 +147,7 @@ static class Factory implements AttributedDirectedGraph.AttributedEdgeFactory<

@SuppressWarnings("type.argument.type.incompatible")
Factory(@UnderInitialization LatticeSpace space) {
this.space = Objects.requireNonNull(space);
this.space = Objects.requireNonNull(space, "space");
}

@Override public Step createEdge(LatticeTable source, LatticeTable target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public abstract class AbstractRelOptPlanner implements RelOptPlanner {
*/
protected AbstractRelOptPlanner(RelOptCostFactory costFactory,
@Nullable Context context) {
this.costFactory = Objects.requireNonNull(costFactory);
this.costFactory = Objects.requireNonNull(costFactory, "costFactory");
if (context == null) {
context = Contexts.empty();
}
Expand Down
Loading

0 comments on commit 12a484a

Please sign in to comment.