[jOOQ/jOOQ#12507] More nullability annotation fixesg

This commit is contained in:
Lukas Eder 2021-10-15 16:28:32 +02:00
parent fd768e310a
commit 562539dcda
7 changed files with 36 additions and 29 deletions

View File

@ -104,6 +104,7 @@ import org.jooq.exception.MappingException;
import org.jooq.tools.JooqLogger;
import org.jooq.tools.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Document;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@ -817,7 +818,7 @@ abstract class AbstractRecord extends AbstractStore implements Record {
Class<E> type = (Class<E>) object.getClass();
try {
return new DefaultRecordMapper<Record, E>((FieldsImpl) fields.fields, type, object, configuration()).map(this);
return (@NotNull E) new DefaultRecordMapper<Record, E>((FieldsImpl) fields.fields, type, object, configuration()).map(this);
}
// Pass MappingExceptions on to client code
@ -900,7 +901,7 @@ abstract class AbstractRecord extends AbstractStore implements Record {
@Override
public final <E> E map(RecordMapper<Record, E> mapper) {
return mapper.map(this);
return (@NotNull E) mapper.map(this);
}
private final void from0(Object source, FieldsImpl f) {

View File

@ -42,6 +42,8 @@ import org.jooq.Context;
import org.jooq.Name;
import org.jooq.impl.QOM.UNotYetImplemented;
import org.jetbrains.annotations.NotNull;
/**
* @author Lukas Eder
*/
@ -60,6 +62,6 @@ final class CharacterSetImpl extends AbstractQueryPart implements CharacterSet,
@Override
public final String getName() {
return name.last();
return (@NotNull String) name.last();
}
}

View File

@ -1389,7 +1389,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
if (parseKeywordIf("OF"))
if (NO_SUPPORT_FOR_UPDATE_OF_FIELDS.contains(parseDialect()))
result.setForUpdateOf(parseList(',', ParseContext::parseTable).toArray(EMPTY_TABLE));
result.setForUpdateOf(parseList(',', t -> t.parseTable()).toArray(EMPTY_TABLE));
else
result.setForUpdateOf(parseList(',', c -> c.parseField()));

View File

@ -933,7 +933,7 @@ final class ResultImpl<R extends Record> extends AbstractResult<R> implements Re
@Override
public final <E> List<E> map(RecordMapper<? super R, E> mapper) {
return Tools.map(this, mapper::map);
return Tools.map(this, t -> mapper.map(t));
}
@Override

View File

@ -604,7 +604,7 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
@Override
default <E> E fetchSingle(RecordMapper<? super R, E> mapper) {
return mapper.map(fetchSingle());
return (@NotNull E) mapper.map(fetchSingle());
}
@Override
@ -1259,13 +1259,15 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
}
@Override
default Object[][] fetchArrays() {
@Nullable
default Object @NotNull [] @NotNull [] fetchArrays() {
return collect(intoArray(new Object[0][], R::intoArray));
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
default R[] fetchArray() {
@NotNull
default R @NotNull [] fetchArray() {
// [#9288] TODO: Create a delayed Collector that can delay the array type lookup until it's available
Result<R> r = fetch();
@ -1287,7 +1289,8 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
@SuppressWarnings("unchecked")
@Override
default Object[] fetchArray(int fieldIndex) {
@Nullable
default Object @NotNull [] fetchArray(int fieldIndex) {
return collect(new DelayedArrayCollector<>(
fields -> (Object[]) Array.newInstance(fields.field(indexOrFail(fields, fieldIndex)).getType(), 0),
(RecordMapper<R, Object>) mapper(fieldIndex)
@ -1295,18 +1298,19 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
}
@Override
default <U> U[] fetchArray(int fieldIndex, Class<? extends U> type) {
default <U> U @NotNull [] fetchArray(int fieldIndex, Class<? extends U> type) {
return collect(Records.intoArray(type, mapper(fieldIndex, Tools.configuration(this), type)));
}
@Override
default <U> U[] fetchArray(int fieldIndex, Converter<?, ? extends U> converter) {
default <U> U @NotNull [] fetchArray(int fieldIndex, Converter<?, ? extends U> converter) {
return collect(Records.intoArray(converter.toType(), mapper(fieldIndex, converter)));
}
@SuppressWarnings("unchecked")
@Override
default Object[] fetchArray(String fieldName) {
@Nullable
default Object @NotNull [] fetchArray(String fieldName) {
return collect(new DelayedArrayCollector<>(
fields -> (Object[]) Array.newInstance(fields.field(indexOrFail(fields, fieldName)).getType(), 0),
(RecordMapper<R, Object>) mapper(fieldName)
@ -1314,18 +1318,19 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
}
@Override
default <U> U[] fetchArray(String fieldName, Class<? extends U> type) {
default <U> U @NotNull [] fetchArray(String fieldName, Class<? extends U> type) {
return collect(Records.intoArray(type, mapper(fieldName, Tools.configuration(this), type)));
}
@Override
default <U> U[] fetchArray(String fieldName, Converter<?, ? extends U> converter) {
default <U> U @NotNull [] fetchArray(String fieldName, Converter<?, ? extends U> converter) {
return collect(Records.intoArray(converter.toType(), mapper(fieldName, converter)));
}
@SuppressWarnings("unchecked")
@Override
default Object[] fetchArray(Name fieldName) {
@Nullable
default Object @NotNull [] fetchArray(Name fieldName) {
return collect(new DelayedArrayCollector<>(
fields -> (Object[]) Array.newInstance(fields.field(indexOrFail(fields, fieldName)).getType(), 0),
(RecordMapper<R, Object>) mapper(fieldName)
@ -1333,27 +1338,27 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
}
@Override
default <U> U[] fetchArray(Name fieldName, Class<? extends U> type) {
default <U> U @NotNull [] fetchArray(Name fieldName, Class<? extends U> type) {
return collect(Records.intoArray(type, mapper(fieldName, Tools.configuration(this), type)));
}
@Override
default <U> U[] fetchArray(Name fieldName, Converter<?, ? extends U> converter) {
default <U> U @NotNull [] fetchArray(Name fieldName, Converter<?, ? extends U> converter) {
return collect(Records.intoArray(converter.toType(), mapper(fieldName, converter)));
}
@Override
default <T> T[] fetchArray(Field<T> field) {
default <T> T @NotNull [] fetchArray(Field<T> field) {
return collect(Records.intoArray(field.getType(), mapper(field)));
}
@Override
default <U> U[] fetchArray(Field<?> field, Class<? extends U> type) {
default <U> U @NotNull [] fetchArray(Field<?> field, Class<? extends U> type) {
return collect(Records.intoArray(type, mapper(field, Tools.configuration(this), type)));
}
@Override
default <T, U> U[] fetchArray(Field<T> field, Converter<? super T, ? extends U> converter) {
default <T, U> U @NotNull [] fetchArray(Field<T> field, Converter<? super T, ? extends U> converter) {
return collect(Records.intoArray(converter.toType(), mapper(field, converter)));
}

View File

@ -172,7 +172,6 @@ import static org.jooq.impl.SQLDataType.JSONB;
import static org.jooq.impl.SQLDataType.OTHER;
import static org.jooq.impl.SQLDataType.VARCHAR;
import static org.jooq.impl.SQLDataType.XML;
import static org.jooq.impl.Tools.map;
import static org.jooq.impl.Tools.DataKey.DATA_BLOCK_NESTING;
import static org.jooq.tools.StringUtils.defaultIfNull;
@ -251,7 +250,6 @@ import org.jooq.Converter;
import org.jooq.ConverterProvider;
import org.jooq.Converters;
import org.jooq.Cursor;
import org.jooq.DMLQuery;
import org.jooq.DSLContext;
import org.jooq.DataType;
import org.jooq.EmbeddableRecord;
@ -314,8 +312,6 @@ import org.jooq.exception.MappingException;
import org.jooq.exception.NoDataFoundException;
import org.jooq.exception.TemplatingException;
import org.jooq.exception.TooManyRowsException;
import org.jooq.impl.QOM.CombinedCondition;
import org.jooq.impl.QOM.CompareCondition;
import org.jooq.impl.ResultsImpl.ResultOrRowsImpl;
import org.jooq.tools.Ints;
import org.jooq.tools.JooqLogger;
@ -328,6 +324,9 @@ import org.jooq.types.UInteger;
import org.jooq.types.ULong;
import org.jooq.types.UShort;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import io.r2dbc.spi.R2dbcException;
/**
@ -1897,7 +1896,7 @@ final class Tools {
return it instanceof Collection ? new ArrayList<>(((Collection<?>) it).size()) : new ArrayList<>();
}
static final <T, R> R apply(T t, Function<? super T, ? extends R> f) {
static final <T, R> R apply(@Nullable T t, Function<? super @NotNull T, ? extends R> f) {
return t == null ? null : f.apply(t);
}

View File

@ -339,22 +339,22 @@ final class WindowDefinitionImpl extends AbstractQueryPart implements WindowDefi
@Override
public final FrameUnits $frameUnits() {
return apply($windowSpecification(), WindowSpecification::$frameUnits);
return apply($windowSpecification(), t -> t.$frameUnits());
}
@Override
public final Integer $frameStart() {
return apply($windowSpecification(), WindowSpecification::$frameStart);
return apply($windowSpecification(), t -> t.$frameStart());
}
@Override
public final Integer $frameEnd() {
return apply($windowSpecification(), WindowSpecification::$frameEnd);
return apply($windowSpecification(), t -> t.$frameEnd());
}
@Override
public final FrameExclude $exclude() {
return apply($windowSpecification(), WindowSpecification::$exclude);
return apply($windowSpecification(), t -> t.$exclude());
}
@Override