Skip to content

Commit ee91580

Browse files
authored
Add nullability annotations, remove @PublicApi annotations for RTDB. (#603)
* Add missing nullability annotations to RTDB. * Remove redundant `@PublicApi` annotations. * Update changelog.
1 parent 23a0fed commit ee91580

20 files changed

+23
-184
lines changed

firebase-database/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
- [changed] Improved error messages for certain Number types that are not
66
supported by our serialization layer (#272).
77
- [internal] Updated the SDK initialization process and removed usages of
8-
deprecated method
8+
deprecated method.
9+
- [changed] Added missing nullability annotations for better Kotlin interop.
10+
- [internal] Removed ``@PublicApi` annotations as they are no longer enforced
11+
and have no semantic meaning.
912

1013
# 16.0.6
1114
- [fixed] Fixed an issue that could cause a NullPointerException during the

firebase-database/firebase-database.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ plugins {
1919
firebaseLibrary {
2020
testLab.enabled = true
2121
publishSources = true
22-
staticAnalysis.disableKotlinInteropLint()
2322
}
2423

2524
android {

firebase-database/src/main/java/com/google/firebase/database/ChildEventListener.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616

1717
import androidx.annotation.NonNull;
1818
import androidx.annotation.Nullable;
19-
import com.google.firebase.annotations.PublicApi;
2019

2120
/**
2221
* Classes implementing this interface can be used to receive events about changes in the child
2322
* locations of a given {@link DatabaseReference DatabaseReference} ref. Attach the listener to a
2423
* location using {@link DatabaseReference#addChildEventListener(ChildEventListener)} and the
2524
* appropriate method will be triggered when changes occur.
2625
*/
27-
@PublicApi
2826
public interface ChildEventListener {
2927

3028
/**
@@ -35,7 +33,6 @@ public interface ChildEventListener {
3533
* @param previousChildName The key name of sibling location ordered before the new child. This
3634
* will be null for the first child node of a location.
3735
*/
38-
@PublicApi
3936
public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String previousChildName);
4037

4138
/**
@@ -45,7 +42,6 @@ public interface ChildEventListener {
4542
* @param previousChildName The key name of sibling location ordered before the child. This will
4643
* be null for the first child node of a location.
4744
*/
48-
@PublicApi
4945
public void onChildChanged(@NonNull DataSnapshot snapshot, @Nullable String previousChildName);
5046

5147
/**
@@ -54,7 +50,6 @@ public interface ChildEventListener {
5450
*
5551
* @param snapshot An immutable snapshot of the data at the child that was removed.
5652
*/
57-
@PublicApi
5853
public void onChildRemoved(@NonNull DataSnapshot snapshot);
5954

6055
/**
@@ -67,7 +62,6 @@ public interface ChildEventListener {
6762
* @param previousChildName The key name of the sibling location ordered before the child
6863
* location. This will be null if this location is ordered first.
6964
*/
70-
@PublicApi
7165
public void onChildMoved(@NonNull DataSnapshot snapshot, @Nullable String previousChildName);
7266

7367
/**
@@ -78,6 +72,5 @@ public interface ChildEventListener {
7872
*
7973
* @param error A description of the error that occurred
8074
*/
81-
@PublicApi
8275
public void onCancelled(@NonNull DatabaseError error);
8376
}

firebase-database/src/main/java/com/google/firebase/database/DataSnapshot.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import androidx.annotation.NonNull;
1818
import androidx.annotation.Nullable;
19-
import com.google.firebase.annotations.PublicApi;
2019
import com.google.firebase.database.core.Path;
2120
import com.google.firebase.database.core.utilities.Validation;
2221
import com.google.firebase.database.core.utilities.encoding.CustomClassMapper;
@@ -39,7 +38,6 @@
3938
* DatabaseReference DatabaseReference} reference (e.g. with {@link
4039
* DatabaseReference#setValue(Object)}).
4140
*/
42-
@PublicApi
4341
public class DataSnapshot {
4442

4543
private final IndexedNode node;
@@ -63,7 +61,6 @@ public class DataSnapshot {
6361
* @return The DataSnapshot for the child location
6462
*/
6563
@NonNull
66-
@PublicApi
6764
public DataSnapshot child(@NonNull String path) {
6865
DatabaseReference childRef = query.child(path);
6966
Node childNode = this.node.getNode().getChild(new Path(path));
@@ -76,7 +73,6 @@ public DataSnapshot child(@NonNull String path) {
7673
* @param path A relative path to the location of child data
7774
* @return Whether or not the specified child location has data
7875
*/
79-
@PublicApi
8076
public boolean hasChild(@NonNull String path) {
8177
if (query.getParent() == null) {
8278
Validation.validateRootPathString(path);
@@ -91,7 +87,6 @@ public boolean hasChild(@NonNull String path) {
9187
*
9288
* @return True if the snapshot has any children, otherwise false
9389
*/
94-
@PublicApi
9590
public boolean hasChildren() {
9691
return node.getNode().getChildCount() > 0;
9792
}
@@ -101,7 +96,6 @@ public boolean hasChildren() {
10196
*
10297
* @return True if the snapshot contains a non-null value, otherwise false
10398
*/
104-
@PublicApi
10599
public boolean exists() {
106100
return !node.getNode().isEmpty();
107101
}
@@ -126,7 +120,6 @@ public boolean exists() {
126120
* location.
127121
*/
128122
@Nullable
129-
@PublicApi
130123
public Object getValue() {
131124
return node.getNode().getValue();
132125
}
@@ -156,7 +149,6 @@ public Object getValue() {
156149
* location.
157150
*/
158151
@Nullable
159-
@PublicApi
160152
public Object getValue(boolean useExportFormat) {
161153
return node.getNode().getValue(useExportFormat);
162154
}
@@ -206,7 +198,6 @@ public Object getValue(boolean useExportFormat) {
206198
* if there is no data at this location.
207199
*/
208200
@Nullable
209-
@PublicApi
210201
public <T> T getValue(@NonNull Class<T> valueType) {
211202
Object value = node.getNode().getValue();
212203
return CustomClassMapper.convertToCustomClass(value, valueType);
@@ -233,14 +224,12 @@ public <T> T getValue(@NonNull Class<T> valueType) {
233224
* there is no data at this location.
234225
*/
235226
@Nullable
236-
@PublicApi
237227
public <T> T getValue(@NonNull GenericTypeIndicator<T> t) {
238228
Object value = node.getNode().getValue();
239229
return CustomClassMapper.convertToCustomClass(value, t);
240230
}
241231

242232
/** @return The number of immediate children in the this snapshot */
243-
@PublicApi
244233
public long getChildrenCount() {
245234
return node.getNode().getChildCount();
246235
}
@@ -251,7 +240,6 @@ public long getChildrenCount() {
251240
* @return A DatabaseReference corresponding to the location that this snapshot came from
252241
*/
253242
@NonNull
254-
@PublicApi
255243
public DatabaseReference getRef() {
256244
return query;
257245
}
@@ -261,7 +249,6 @@ public DatabaseReference getRef() {
261249
* to the database root.
262250
*/
263251
@Nullable
264-
@PublicApi
265252
public String getKey() {
266253
return query.getKey();
267254
}
@@ -277,7 +264,6 @@ public String getKey() {
277264
* @return The immediate children of this snapshot
278265
*/
279266
@NonNull
280-
@PublicApi
281267
public Iterable<DataSnapshot> getChildren() {
282268
final Iterator<NamedNode> iter = node.iterator();
283269
return new Iterable<DataSnapshot>() {
@@ -321,7 +307,6 @@ public void remove() {
321307
* @return the priority of the data contained in this snapshot as a native type
322308
*/
323309
@Nullable
324-
@PublicApi
325310
public Object getPriority() {
326311
Object priority = node.getNode().getPriority().getValue();
327312
if (priority instanceof Long) {

firebase-database/src/main/java/com/google/firebase/database/DatabaseError.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import androidx.annotation.NonNull;
1818
import androidx.annotation.RestrictTo;
19-
import com.google.firebase.annotations.PublicApi;
2019
import java.io.PrintWriter;
2120
import java.io.StringWriter;
2221
import java.util.HashMap;
@@ -26,49 +25,48 @@
2625
* Instances of DatabaseError are passed to callbacks when an operation failed. They contain a
2726
* description of the specific error that occurred.
2827
*/
29-
@PublicApi
3028
public class DatabaseError {
3129

3230
/** <strong>Internal use</strong> */
33-
@PublicApi public static final int DATA_STALE = -1;
31+
public static final int DATA_STALE = -1;
3432
/** The server indicated that this operation failed */
35-
@PublicApi public static final int OPERATION_FAILED = -2;
33+
public static final int OPERATION_FAILED = -2;
3634
/** This client does not have permission to perform this operation */
37-
@PublicApi public static final int PERMISSION_DENIED = -3;
35+
public static final int PERMISSION_DENIED = -3;
3836
/** The operation had to be aborted due to a network disconnect */
39-
@PublicApi public static final int DISCONNECTED = -4;
37+
public static final int DISCONNECTED = -4;
4038

4139
// Preempted was removed, this is for here for completeness and history
4240
// public static final int PREEMPTED = -5;
4341

4442
/** The supplied auth token has expired */
45-
@PublicApi public static final int EXPIRED_TOKEN = -6;
43+
public static final int EXPIRED_TOKEN = -6;
4644
/**
4745
* The specified authentication token is invalid. This can occur when the token is malformed,
4846
* expired, or the secret that was used to generate it has been revoked.
4947
*/
50-
@PublicApi public static final int INVALID_TOKEN = -7;
48+
public static final int INVALID_TOKEN = -7;
5149
/** The transaction had too many retries */
52-
@PublicApi public static final int MAX_RETRIES = -8;
50+
public static final int MAX_RETRIES = -8;
5351
/** The transaction was overridden by a subsequent set */
54-
@PublicApi public static final int OVERRIDDEN_BY_SET = -9;
52+
public static final int OVERRIDDEN_BY_SET = -9;
5553
/** The service is unavailable */
56-
@PublicApi public static final int UNAVAILABLE = -10;
54+
public static final int UNAVAILABLE = -10;
5755
/** An exception occurred in user code */
58-
@PublicApi public static final int USER_CODE_EXCEPTION = -11;
56+
public static final int USER_CODE_EXCEPTION = -11;
5957

6058
// client codes
6159
/** The operation could not be performed due to a network error. */
62-
@PublicApi public static final int NETWORK_ERROR = -24;
60+
public static final int NETWORK_ERROR = -24;
6361

6462
/** The write was canceled locally */
65-
@PublicApi public static final int WRITE_CANCELED = -25;
63+
public static final int WRITE_CANCELED = -25;
6664

6765
/**
6866
* An unknown error occurred. Please refer to the error message and error details for more
6967
* information.
7068
*/
71-
@PublicApi public static final int UNKNOWN_ERROR = -999;
69+
public static final int UNKNOWN_ERROR = -999;
7270

7371
private static final Map<Integer, String> errorReasons = new HashMap<Integer, String>();
7472

@@ -175,8 +173,8 @@ public static DatabaseError fromStatus(String status, String reason, String deta
175173
return new DatabaseError(code, message, details);
176174
}
177175

178-
@PublicApi
179-
public static DatabaseError fromException(Throwable e) {
176+
@NonNull
177+
public static DatabaseError fromException(@NonNull Throwable e) {
180178
StringWriter stringWriter = new StringWriter();
181179
PrintWriter printWriter = new PrintWriter(stringWriter);
182180
e.printStackTrace(printWriter);
@@ -199,21 +197,18 @@ private DatabaseError(int code, String message, String details) {
199197
}
200198

201199
/** @return One of the defined status codes, depending on the error */
202-
@PublicApi
203200
public int getCode() {
204201
return code;
205202
}
206203

207204
/** @return A human-readable description of the error */
208205
@NonNull
209-
@PublicApi
210206
public String getMessage() {
211207
return message;
212208
}
213209

214210
/** @return Human-readable details on the error and additional information, e.g. links to docs; */
215211
@NonNull
216-
@PublicApi
217212
public String getDetails() {
218213
return details;
219214
}
@@ -229,7 +224,7 @@ public String toString() {
229224
*
230225
* @return An exception wrapping this error, with an appropriate message and no stack trace.
231226
*/
232-
@PublicApi
227+
@NonNull
233228
public DatabaseException toException() {
234229
return new DatabaseException("Firebase Database error: " + message);
235230
}

firebase-database/src/main/java/com/google/firebase/database/DatabaseException.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
package com.google.firebase.database;
1616

1717
import androidx.annotation.RestrictTo;
18-
import com.google.firebase.annotations.PublicApi;
1918

2019
/**
2120
* This error is thrown when the Firebase Database library is unable to operate on the input it has
2221
* been given.
2322
*/
24-
@PublicApi
2523
public class DatabaseException extends RuntimeException {
2624

2725
/**

0 commit comments

Comments
 (0)