Skip to content

Commit 8ac8d66

Browse files
committed
Add nullability to package org.firebirdsql.jdbc
1 parent 5cae498 commit 8ac8d66

56 files changed

Lines changed: 211 additions & 240 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/org/firebirdsql/ds/FBXAConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public final class FBXAConnection extends FBPooledConnection implements XAConnec
2424

2525
private final WeakReference<FBManagedConnection> mc;
2626

27-
FBXAConnection(FBConnection connection) {
27+
FBXAConnection(FBConnection connection) throws SQLException {
2828
super(connection);
2929
mc = new WeakReference<>(connection.getManagedConnection());
3030
}

src/main/org/firebirdsql/gds/ng/AbstractImmutableAttachProperties.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ protected AbstractImmutableAttachProperties(IAttachProperties<T> src) {
4848
: unmodifiableMap(new HashMap<>(src.connectionPropertyValues()));
4949
}
5050

51+
/**
52+
* Constructor for an empty immutable attach properties instance.
53+
*
54+
* @since 7
55+
*/
56+
AbstractImmutableAttachProperties() {
57+
propValues = Map.of();
58+
}
59+
5160
@Override
5261
public final @Nullable String getProperty(String name) {
5362
ConnectionProperty property = property(name);

src/main/org/firebirdsql/gds/ng/FbImmutableConnectionProperties.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
public final class FbImmutableConnectionProperties extends AbstractImmutableAttachProperties<IConnectionProperties>
1515
implements IConnectionProperties {
1616

17+
private static final FbImmutableConnectionProperties EMPTY = new FbImmutableConnectionProperties();
18+
1719
/**
1820
* Copy constructor for FbConnectionProperties.
1921
* <p>
@@ -28,6 +30,22 @@ public FbImmutableConnectionProperties(IConnectionProperties src) {
2830
super(src);
2931
}
3032

33+
/**
34+
* Constructor for an empty immutable connection properties instance.
35+
*
36+
* @since 7
37+
*/
38+
private FbImmutableConnectionProperties() {
39+
}
40+
41+
/**
42+
* @return a possibly cached empty immutable connection properties instance
43+
* @since 7
44+
*/
45+
public static FbImmutableConnectionProperties empty() {
46+
return EMPTY;
47+
}
48+
3149
@Override
3250
public IConnectionProperties asImmutable() {
3351
// Immutable already, so just return this

src/main/org/firebirdsql/jdbc/AbstractFetcher.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
SPDX-FileCopyrightText: Copyright 2002 Nikolay Samofatov
55
SPDX-FileCopyrightText: Copyright 2003 Ryan Baldwin
66
SPDX-FileCopyrightText: Copyright 2005 Gabriel Reid
7-
SPDX-FileCopyrightText: Copyright 2012-2024 Mark Rotteveel
7+
SPDX-FileCopyrightText: Copyright 2012-2026 Mark Rotteveel
88
SPDX-License-Identifier: LGPL-2.1-or-later
99
*/
1010
package org.firebirdsql.jdbc;
@@ -16,7 +16,6 @@
1616
import org.firebirdsql.gds.ng.fields.RowValue;
1717
import org.firebirdsql.jdbc.FBObjectListener.FetcherListener;
1818
import org.firebirdsql.util.InternalApi;
19-
import org.jspecify.annotations.NullMarked;
2019
import org.jspecify.annotations.Nullable;
2120

2221
import java.sql.SQLException;
@@ -30,7 +29,6 @@
3029
* @since 6
3130
*/
3231
@InternalApi
33-
@NullMarked
3432
abstract sealed class AbstractFetcher implements FBFetcher
3533
permits FBCachedFetcher, FBServerScrollFetcher, FBStatementFetcher {
3634

src/main/org/firebirdsql/jdbc/AbstractFieldMetaData.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.firebirdsql.gds.ng.fields.RowDescriptor;
2020
import org.firebirdsql.jdbc.field.JdbcTypeConverter;
2121
import org.firebirdsql.util.InternalApi;
22-
import org.jspecify.annotations.NullMarked;
2322
import org.jspecify.annotations.Nullable;
2423

2524
import java.sql.SQLException;
@@ -44,7 +43,6 @@
4443
* @since 3.0
4544
*/
4645
@InternalApi
47-
@NullMarked
4846
public abstract class AbstractFieldMetaData implements Wrapper {
4947

5048
private final RowDescriptor rowDescriptor;

src/main/org/firebirdsql/jdbc/AbstractStatement.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.firebirdsql.gds.ng.FbStatement;
1515
import org.firebirdsql.gds.ng.LockCloseable;
1616
import org.firebirdsql.util.InternalApi;
17-
import org.jspecify.annotations.NullMarked;
1817
import org.jspecify.annotations.Nullable;
1918

2019
import java.sql.SQLException;
@@ -36,7 +35,6 @@
3635
* @since 6
3736
*/
3837
@InternalApi
39-
@NullMarked
4038
public abstract class AbstractStatement implements Statement, FirebirdStatement {
4139

4240
private static final AtomicInteger STATEMENT_ID_GENERATOR = new AtomicInteger();

src/main/org/firebirdsql/jdbc/Batch.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package org.firebirdsql.jdbc;
44

55
import org.firebirdsql.gds.ng.fields.RowValue;
6-
import org.jspecify.annotations.NullMarked;
76

87
import java.sql.BatchUpdateException;
98
import java.sql.SQLException;
@@ -15,7 +14,6 @@
1514
* @author Mark Rotteveel
1615
* @since 5
1716
*/
18-
@NullMarked
1917
interface Batch {
2018

2119
/**

src/main/org/firebirdsql/jdbc/ClientInfoProvider.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// SPDX-FileCopyrightText: Copyright 2023-2025 Mark Rotteveel
1+
// SPDX-FileCopyrightText: Copyright 2023-2026 Mark Rotteveel
22
// SPDX-License-Identifier: LGPL-2.1-or-later
33
package org.firebirdsql.jdbc;
44

55
import org.firebirdsql.gds.ISCConstants;
66
import org.firebirdsql.gds.ng.FbExceptionBuilder;
7+
import org.jspecify.annotations.Nullable;
78

89
import java.sql.ClientInfoStatus;
910
import java.sql.SQLClientInfoException;
@@ -55,7 +56,7 @@ final class ClientInfoProvider {
5556
// Holds statement used for setting or retrieving client info properties.
5657
private final MetadataStatementHolder statementHolder;
5758
// if null, use DEFAULT_CLIENT_INFO_PROPERTIES
58-
private Set<ClientInfoProperty> knownProperties;
59+
private @Nullable Set<ClientInfoProperty> knownProperties;
5960

6061
ClientInfoProvider(FBConnection connection) throws SQLException {
6162
connection.checkValidity();
@@ -154,7 +155,7 @@ Collection<ClientInfoProperty> getDefaultClientInfoProperties() {
154155
* Implementation of {@link FBConnection#getClientInfo(String)}.
155156
*/
156157
@SuppressWarnings("SqlSourceToSinkFlow")
157-
public String getClientInfo(String name) throws SQLException {
158+
public @Nullable String getClientInfo(String name) throws SQLException {
158159
ClientInfoProperty property;
159160
try {
160161
property = ClientInfoProperty.parse(name);
@@ -270,6 +271,7 @@ public void setClientInfo(String name, String value) throws SQLException {
270271
SQLException forMessage = FbExceptionBuilder.forException(jb_clientInfoInvalidPropertyName)
271272
.messageParameter(name)
272273
.toSQLException();
274+
//noinspection DataFlowIssue : null-check for robustness
273275
throw new SQLClientInfoException(forMessage.getMessage(), forMessage.getSQLState(),
274276
forMessage.getErrorCode(),
275277
Map.of(requireNonNullElse(name, "<null>"), ClientInfoStatus.REASON_UNKNOWN), e);
@@ -298,7 +300,7 @@ public void setClientInfo(Properties properties) throws SQLException {
298300
// Include USER_SESSION, and USER_TRANSACTION if not in auto-commit
299301
Predicate<ClientInfoProperty> includePropertyPredicate = property ->
300302
USER_SESSION.equals(property.context) || !autoCommit && USER_TRANSACTION.equals(property.context);
301-
var propertyValues = new HashMap<ClientInfoProperty, String>();
303+
var propertyValues = new HashMap<ClientInfoProperty, @Nullable String>();
302304
// Populating with null to clear properties not included in parameter properties
303305
getKnownProperties().stream()
304306
.filter(includePropertyPredicate)
@@ -316,7 +318,7 @@ public void setClientInfo(Properties properties) throws SQLException {
316318
}
317319

318320
@SuppressWarnings("SqlSourceToSinkFlow")
319-
private void executeSetClientInfo(Map<ClientInfoProperty, String> propertyValues) throws SQLException {
321+
private void executeSetClientInfo(Map<ClientInfoProperty, @Nullable String> propertyValues) throws SQLException {
320322
QuoteStrategy quoteStrategy = connection.getQuoteStrategy();
321323
var sb = new StringBuilder("""
322324
execute block
@@ -437,7 +439,7 @@ StringBuilder appendAsGetContext(StringBuilder sb, QuoteStrategy quoteStrategy)
437439
* value to set, use {@code null} to set SQL {@code NULL}
438440
* @return {@code sb} for chaining calls
439441
*/
440-
StringBuilder appendAsSetContext(StringBuilder sb, QuoteStrategy quoteStrategy, String value) {
442+
StringBuilder appendAsSetContext(StringBuilder sb, QuoteStrategy quoteStrategy, @Nullable String value) {
441443
// 30 = 16 (prefix) + 9 (6 quotes, 2 commas, and closing parenthesis) + space for five quotes to escape
442444
sb.ensureCapacity(
443445
sb.length() + 30 + context.length() + name.length() + (value != null ? value.length() : 4));

src/main/org/firebirdsql/jdbc/DbMetadataMediator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.firebirdsql.gds.ng.fields.RowDescriptorBuilder;
1111
import org.firebirdsql.util.FirebirdSupportInfo;
1212
import org.firebirdsql.util.InternalApi;
13-
import org.jspecify.annotations.NullMarked;
1413
import org.jspecify.annotations.NullUnmarked;
1514

1615
import java.nio.charset.StandardCharsets;
@@ -31,7 +30,6 @@
3130
* @since 4.0
3231
*/
3332
@InternalApi
34-
@NullMarked
3533
public abstract class DbMetadataMediator {
3634

3735
private static final DatatypeCoder datatypeCoder =
@@ -70,7 +68,7 @@ public static RowDescriptorBuilder newRowDescriptorBuilder(int size) {
7068
* @return GDSType of the current connection
7169
*/
7270
@NullUnmarked
73-
public abstract GDSType getGDSType();
71+
public abstract GDSType getGDSType() throws SQLException;
7472

7573
/**
7674
* @return value of the {@code useCatalogAsPackage} connection property if packages are supported, otherwise

src/main/org/firebirdsql/jdbc/FBBlob.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
* </p>
6565
*/
6666
@InternalApi
67-
@NullMarked
6867
public final class FBBlob implements FirebirdBlob, TransactionListener {
6968

7069
private static final System.Logger logger = System.getLogger(FBBlob.class.getName());
@@ -649,7 +648,6 @@ public void copyCharacterStream(Reader reader) throws SQLException {
649648
}
650649

651650
@Override
652-
@NullMarked
653651
public void transactionStateChanged(FbTransaction transaction, TransactionState newState,
654652
TransactionState previousState) {
655653
if (newState == TransactionState.COMMITTED || newState == TransactionState.ROLLED_BACK) {

0 commit comments

Comments
 (0)