mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add parentheses to fix UnexpectedLoaderException message logic
These were missing in 5211ff0dc1
Without these, the `": null"` is still logged (but the `"Unexpected
IllegalStateException"` bit is not), because the **whole** string
concatenation is compared to null as the boolean condition of the
ternary, and this condition is always false (the result of a string
concatentation is never `null`) i.e. (with excess parentheses for
clarity):
```
(("Unexpected " + cause.getClass().getSimpleName() + cause.getMessage()) != null)
? ": " + cause.getMessage()
: ""
```
Also add a test because obviously this isn't as simple as I'd thought.
PiperOrigin-RevId: 593079975
This commit is contained in:
parent
09bde8053d
commit
a496bbd777
2 changed files with 51 additions and 3 deletions
|
|
@ -48,9 +48,9 @@ public final class Loader implements LoaderErrorThrower {
|
||||||
|
|
||||||
public UnexpectedLoaderException(Throwable cause) {
|
public UnexpectedLoaderException(Throwable cause) {
|
||||||
super(
|
super(
|
||||||
"Unexpected " + cause.getClass().getSimpleName() + cause.getMessage() != null
|
"Unexpected "
|
||||||
? ": " + cause.getMessage()
|
+ cause.getClass().getSimpleName()
|
||||||
: "",
|
+ (cause.getMessage() != null ? ": " + cause.getMessage() : ""),
|
||||||
cause);
|
cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package androidx.media3.exoplayer.upstream;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import androidx.media3.exoplayer.upstream.Loader.UnexpectedLoaderException;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
|
/** Tests for {@link UnexpectedLoaderException}. */
|
||||||
|
@RunWith(JUnit4.class)
|
||||||
|
public class UnexpectedLoaderExceptionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void causeWithMessage_messageAppended() {
|
||||||
|
UnexpectedLoaderException unexpectedLoaderException =
|
||||||
|
new UnexpectedLoaderException(new IllegalStateException("test message"));
|
||||||
|
|
||||||
|
assertThat(unexpectedLoaderException)
|
||||||
|
.hasMessageThat()
|
||||||
|
.isEqualTo("Unexpected IllegalStateException: test message");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void causeWithoutMessage_noMessageAppended() {
|
||||||
|
UnexpectedLoaderException unexpectedLoaderException =
|
||||||
|
new UnexpectedLoaderException(new IllegalStateException());
|
||||||
|
|
||||||
|
assertThat(unexpectedLoaderException)
|
||||||
|
.hasMessageThat()
|
||||||
|
.isEqualTo("Unexpected IllegalStateException");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue