Commit d4975415 by aquilescanta Committed by bachinger

Remove calls to initCause

In favor of setting the cause in the constructor, which allows
some code simplifications.

PiperOrigin-RevId: 387062636
parent f53f44c9
...@@ -713,18 +713,18 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource { ...@@ -713,18 +713,18 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
responseBody = Util.EMPTY_BYTE_ARRAY; responseBody = Util.EMPTY_BYTE_ARRAY;
} }
InvalidResponseCodeException exception = @Nullable
new InvalidResponseCodeException( IOException cause =
responseCode == 416
? new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE)
: null;
throw new InvalidResponseCodeException(
responseCode, responseCode,
responseInfo.getHttpStatusText(), responseInfo.getHttpStatusText(),
cause,
responseHeaders, responseHeaders,
dataSpec, dataSpec,
responseBody); responseBody);
if (responseCode == 416) {
exception.initCause(
new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE));
}
throw exception;
} }
// Check for a valid content type. // Check for a valid content type.
...@@ -1188,6 +1188,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource { ...@@ -1188,6 +1188,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
new InvalidResponseCodeException( new InvalidResponseCodeException(
responseCode, responseCode,
info.getHttpStatusText(), info.getHttpStatusText(),
/* cause= */ null,
info.getAllHeaders(), info.getAllHeaders(),
dataSpec, dataSpec,
/* responseBody= */ Util.EMPTY_BYTE_ARRAY); /* responseBody= */ Util.EMPTY_BYTE_ARRAY);
......
...@@ -324,14 +324,13 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource { ...@@ -324,14 +324,13 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
} }
Map<String, List<String>> headers = response.headers().toMultimap(); Map<String, List<String>> headers = response.headers().toMultimap();
closeConnectionQuietly(); closeConnectionQuietly();
InvalidResponseCodeException exception = @Nullable
new InvalidResponseCodeException( IOException cause =
responseCode, response.message(), headers, dataSpec, errorResponseBody); responseCode == 416
if (responseCode == 416) { ? new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE)
exception.initCause( : null;
new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE)); throw new InvalidResponseCodeException(
} responseCode, response.message(), cause, headers, dataSpec, errorResponseBody);
throw exception;
} }
// Check for a valid content type. // Check for a valid content type.
......
...@@ -76,7 +76,7 @@ public class DataSourceException extends IOException { ...@@ -76,7 +76,7 @@ public class DataSourceException extends IOException {
* PlaybackException.ErrorCode}. * PlaybackException.ErrorCode}.
*/ */
public DataSourceException( public DataSourceException(
String message, Throwable cause, @PlaybackException.ErrorCode int reason) { String message, @Nullable Throwable cause, @PlaybackException.ErrorCode int reason) {
super(message, cause); super(message, cause);
this.reason = reason; this.reason = reason;
} }
......
...@@ -400,14 +400,13 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou ...@@ -400,14 +400,13 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
errorResponseBody = Util.EMPTY_BYTE_ARRAY; errorResponseBody = Util.EMPTY_BYTE_ARRAY;
} }
closeConnectionQuietly(); closeConnectionQuietly();
InvalidResponseCodeException exception = @Nullable
new InvalidResponseCodeException( IOException cause =
responseCode, responseMessage, headers, dataSpec, errorResponseBody); responseCode == 416
if (responseCode == 416) { ? new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE)
exception.initCause( : null;
new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE)); throw new InvalidResponseCodeException(
} responseCode, responseMessage, cause, headers, dataSpec, errorResponseBody);
throw exception;
} }
// Check for a valid content type. // Check for a valid content type.
......
...@@ -317,7 +317,7 @@ public interface HttpDataSource extends DataSource { ...@@ -317,7 +317,7 @@ public interface HttpDataSource extends DataSource {
*/ */
public HttpDataSourceException( public HttpDataSourceException(
String message, String message,
IOException cause, @Nullable IOException cause,
DataSpec dataSpec, DataSpec dataSpec,
@PlaybackException.ErrorCode int errorCode, @PlaybackException.ErrorCode int errorCode,
@Type int type) { @Type int type) {
...@@ -386,7 +386,8 @@ public interface HttpDataSource extends DataSource { ...@@ -386,7 +386,8 @@ public interface HttpDataSource extends DataSource {
public final byte[] responseBody; public final byte[] responseBody;
/** /**
* @deprecated Use {@link #InvalidResponseCodeException(int, String, Map, DataSpec, byte[])}. * @deprecated Use {@link #InvalidResponseCodeException(int, String, IOException, Map, DataSpec,
* byte[])}.
*/ */
@Deprecated @Deprecated
public InvalidResponseCodeException( public InvalidResponseCodeException(
...@@ -394,13 +395,15 @@ public interface HttpDataSource extends DataSource { ...@@ -394,13 +395,15 @@ public interface HttpDataSource extends DataSource {
this( this(
responseCode, responseCode,
/* responseMessage= */ null, /* responseMessage= */ null,
/* cause= */ null,
headerFields, headerFields,
dataSpec, dataSpec,
/* responseBody= */ Util.EMPTY_BYTE_ARRAY); /* responseBody= */ Util.EMPTY_BYTE_ARRAY);
} }
/** /**
* @deprecated Use {@link #InvalidResponseCodeException(int, String, Map, DataSpec, byte[])}. * @deprecated Use {@link #InvalidResponseCodeException(int, String, IOException, Map, DataSpec,
* byte[])}.
*/ */
@Deprecated @Deprecated
public InvalidResponseCodeException( public InvalidResponseCodeException(
...@@ -411,6 +414,7 @@ public interface HttpDataSource extends DataSource { ...@@ -411,6 +414,7 @@ public interface HttpDataSource extends DataSource {
this( this(
responseCode, responseCode,
responseMessage, responseMessage,
/* cause= */ null,
headerFields, headerFields,
dataSpec, dataSpec,
/* responseBody= */ Util.EMPTY_BYTE_ARRAY); /* responseBody= */ Util.EMPTY_BYTE_ARRAY);
...@@ -419,11 +423,13 @@ public interface HttpDataSource extends DataSource { ...@@ -419,11 +423,13 @@ public interface HttpDataSource extends DataSource {
public InvalidResponseCodeException( public InvalidResponseCodeException(
int responseCode, int responseCode,
@Nullable String responseMessage, @Nullable String responseMessage,
@Nullable IOException cause,
Map<String, List<String>> headerFields, Map<String, List<String>> headerFields,
DataSpec dataSpec, DataSpec dataSpec,
byte[] responseBody) { byte[] responseBody) {
super( super(
"Response code: " + responseCode, "Response code: " + responseCode,
cause,
dataSpec, dataSpec,
PlaybackException.ERROR_CODE_IO_BAD_HTTP_STATUS, PlaybackException.ERROR_CODE_IO_BAD_HTTP_STATUS,
TYPE_OPEN); TYPE_OPEN);
......
...@@ -296,6 +296,7 @@ public final class DefaultLoadErrorHandlingPolicyTest { ...@@ -296,6 +296,7 @@ public final class DefaultLoadErrorHandlingPolicyTest {
return new InvalidResponseCodeException( return new InvalidResponseCodeException(
statusCode, statusCode,
message, message,
/* cause= */ null,
Collections.emptyMap(), Collections.emptyMap(),
new DataSpec(Uri.EMPTY), new DataSpec(Uri.EMPTY),
/* responseBody= */ Util.EMPTY_BYTE_ARRAY); /* responseBody= */ Util.EMPTY_BYTE_ARRAY);
......
...@@ -339,6 +339,7 @@ public class DefaultDashChunkSourceTest { ...@@ -339,6 +339,7 @@ public class DefaultDashChunkSourceTest {
new HttpDataSource.InvalidResponseCodeException( new HttpDataSource.InvalidResponseCodeException(
httpResponseCode, httpResponseCode,
/* responseMessage= */ null, /* responseMessage= */ null,
/* cause= */ null,
ImmutableMap.of(), ImmutableMap.of(),
dataSpec, dataSpec,
new byte[0]); new byte[0]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment