Skip to content

Commit f805e70

Browse files
authored
fix: Avoid creating message string prematurely for streaming calls (#3622)
- Creating the string message prematurely puts a lot of strain on the JVM and GC, switch to the format version of `Preconditions.checkState` which only constructs the string if we throw the exception - Issue: #3621 Thank you for opening a Pull Request! Before submitting your PR, please read our [contributing guidelines](https://github.com/googleapis/gapic-generator-java/blob/main/CONTRIBUTING.md). There are a few things you can do to make sure it goes smoothly: - [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/gapic-generator-java/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) Fixes #3621 ☕️
1 parent c11360e commit f805e70

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

gax-java/gax/src/main/java/com/google/api/gax/rpc/StateCheckingResponseObserver.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public abstract class StateCheckingResponseObserver<V> implements ResponseObserv
4343
* ensuring consistent state.
4444
*/
4545
public final void onStart(StreamController controller) {
46-
Preconditions.checkState(!isStarted, getClass() + " is already started.");
46+
Preconditions.checkState(!isStarted, "%s is already started.", getClass());
4747
isStarted = true;
4848

4949
onStartImpl(controller);
@@ -56,7 +56,7 @@ public final void onStart(StreamController controller) {
5656
* consistent state.
5757
*/
5858
public final void onResponse(V response) {
59-
Preconditions.checkState(!isClosed, getClass() + " received a response after being closed.");
59+
Preconditions.checkState(!isClosed, "%s received a response after being closed.", getClass());
6060
onResponseImpl(response);
6161
}
6262

@@ -67,7 +67,7 @@ public final void onResponse(V response) {
6767
* state.
6868
*/
6969
public final void onComplete() {
70-
Preconditions.checkState(!isClosed, getClass() + " tried to double close.");
70+
Preconditions.checkState(!isClosed, "%s tried to double close.", getClass());
7171
isClosed = true;
7272
onCompleteImpl();
7373
}
@@ -79,7 +79,7 @@ public final void onComplete() {
7979
* consistent state.
8080
*/
8181
public final void onError(Throwable t) {
82-
Preconditions.checkState(!isClosed, getClass() + " received error after being closed", t);
82+
Preconditions.checkState(!isClosed, "%s received error after being closed", t, getClass());
8383
isClosed = true;
8484
onErrorImpl(t);
8585
}

0 commit comments

Comments
 (0)