Skip to content

fix: FirebaseOptions: move default initialization from Builder #592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/main/java/com/google/firebase/FirebaseOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ private FirebaseOptions(@NonNull final FirebaseOptions.Builder builder) {
this.serviceAccountId = null;
}
this.storageBucket = builder.storageBucket;
this.httpTransport = checkNotNull(builder.httpTransport,
"FirebaseOptions must be initialized with a non-null HttpTransport.");
this.jsonFactory = checkNotNull(builder.jsonFactory,
"FirebaseOptions must be initialized with a non-null JsonFactory.");
this.threadManager = checkNotNull(builder.threadManager,
"FirebaseOptions must be initialized with a non-null ThreadManager.");
this.httpTransport = builder.httpTransport != null ? builder.httpTransport
: ApiClientUtils.getDefaultTransport();
this.jsonFactory = builder.jsonFactory != null ? builder.jsonFactory
: ApiClientUtils.getDefaultJsonFactory();
this.threadManager = builder.threadManager != null ? builder.threadManager
: FirebaseThreadManagers.DEFAULT_THREAD_MANAGER;
checkArgument(builder.connectTimeout >= 0);
this.connectTimeout = builder.connectTimeout;
checkArgument(builder.readTimeout >= 0);
Expand Down Expand Up @@ -255,9 +255,9 @@ public static final class Builder {
private String serviceAccountId;
private Supplier<GoogleCredentials> credentialsSupplier;
private FirestoreOptions firestoreOptions;
private HttpTransport httpTransport = ApiClientUtils.getDefaultTransport();
private JsonFactory jsonFactory = ApiClientUtils.getDefaultJsonFactory();
private ThreadManager threadManager = FirebaseThreadManagers.DEFAULT_THREAD_MANAGER;
private HttpTransport httpTransport;
private JsonFactory jsonFactory;
private ThreadManager threadManager;
private int connectTimeout;
private int readTimeout;

Expand Down Expand Up @@ -421,7 +421,8 @@ public Builder setServiceAccountId(@NonNull String serviceAccountId) {
* @return This <code>Builder</code> instance is returned so subsequent calls can be chained.
*/
public Builder setHttpTransport(HttpTransport httpTransport) {
this.httpTransport = httpTransport;
this.httpTransport = checkNotNull(httpTransport,
"FirebaseOptions must be initialized with a non-null HttpTransport.");
return this;
}

Expand All @@ -433,7 +434,8 @@ public Builder setHttpTransport(HttpTransport httpTransport) {
* @return This <code>Builder</code> instance is returned so subsequent calls can be chained.
*/
public Builder setJsonFactory(JsonFactory jsonFactory) {
this.jsonFactory = jsonFactory;
this.jsonFactory = checkNotNull(jsonFactory,
"FirebaseOptions must be initialized with a non-null JsonFactory.");
return this;
}

Expand All @@ -445,7 +447,8 @@ public Builder setJsonFactory(JsonFactory jsonFactory) {
* @return This <code>Builder</code> instance is returned so subsequent calls can be chained.
*/
public Builder setThreadManager(ThreadManager threadManager) {
this.threadManager = threadManager;
this.threadManager = checkNotNull(threadManager,
"FirebaseOptions must be initialized with a non-null ThreadManager.");
return this;
}

Expand Down