Skip to content

Commit 65d6de2

Browse files
authored
Merge pull request hub4j#1311 from hub4j/dependabot/maven/com.github.spotbugs-spotbugs-maven-plugin-4.5.0.0
Chore(deps): Bump spotbugs-maven-plugin from 4.4.2.2 to 4.5.0.0
2 parents 554668b + 8aeacf3 commit 65d6de2

File tree

5 files changed

+46
-25
lines changed

5 files changed

+46
-25
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333

3434
<properties>
3535
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
36-
<spotbugs-maven-plugin.version>4.4.2.2</spotbugs-maven-plugin.version>
37-
<spotbugs.version>4.4.2</spotbugs.version>
36+
<spotbugs-maven-plugin.version>4.5.0.0</spotbugs-maven-plugin.version>
37+
<spotbugs.version>4.5.0</spotbugs.version>
3838
<spotbugs-maven-plugin.failOnError>true</spotbugs-maven-plugin.failOnError>
3939
<hamcrest.version>2.2</hamcrest.version>
4040
<okhttp3.version>4.9.2</okhttp3.version>

src/main/java/org/kohsuke/github/GitHubClient.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -578,20 +578,12 @@ private void detectInvalidCached404Response(GitHubConnectorResponse connectorRes
578578
private void noteRateLimit(@Nonnull RateLimitTarget rateLimitTarget,
579579
@Nonnull GitHubConnectorResponse connectorResponse) {
580580
try {
581-
String limitString = Objects.requireNonNull(connectorResponse.header("X-RateLimit-Limit"),
582-
"Missing X-RateLimit-Limit");
583-
String remainingString = Objects.requireNonNull(connectorResponse.header("X-RateLimit-Remaining"),
584-
"Missing X-RateLimit-Remaining");
585-
String resetString = Objects.requireNonNull(connectorResponse.header("X-RateLimit-Reset"),
586-
"Missing X-RateLimit-Reset");
587-
int limit, remaining;
588-
long reset;
589-
limit = Integer.parseInt(limitString);
590-
remaining = Integer.parseInt(remainingString);
591-
reset = Long.parseLong(resetString);
581+
int limit = connectorResponse.parseInt("X-RateLimit-Limit");
582+
int remaining = connectorResponse.parseInt("X-RateLimit-Remaining");
583+
int reset = connectorResponse.parseInt("X-RateLimit-Reset");
592584
GHRateLimit.Record observed = new GHRateLimit.Record(limit, remaining, reset, connectorResponse);
593585
updateRateLimit(GHRateLimit.fromRecord(observed, rateLimitTarget));
594-
} catch (NumberFormatException | NullPointerException e) {
586+
} catch (NumberFormatException e) {
595587
LOGGER.log(FINEST, "Missing or malformed X-RateLimit header: ", e);
596588
}
597589
}

src/main/java/org/kohsuke/github/GitHubResponse.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ static <T> T parseBody(GitHubConnectorResponse connectorResponse, T instance) th
122122
/**
123123
* Gets the body of the response as a {@link String}.
124124
*
125+
* @param connectorResponse
126+
* the response to read
125127
* @return the body of the response as a {@link String}.
126128
* @throws IOException
127129
* if an I/O Exception occurs.
128-
* @param connectorResponse
129130
*/
130131
@Nonnull
131132
static String getBodyAsString(GitHubConnectorResponse connectorResponse) throws IOException {
@@ -138,15 +139,16 @@ static String getBodyAsString(GitHubConnectorResponse connectorResponse) throws
138139
/**
139140
* Gets the body of the response as a {@link String}.
140141
*
142+
* @param connectorResponse
143+
* the response to read
141144
* @return the body of the response as a {@link String}.
142145
* @throws IOException
143146
* if an I/O Exception occurs.
144-
* @param connectorResponse
145147
*/
146148
static String getBodyAsStringOrNull(GitHubConnectorResponse connectorResponse) {
147149
try {
148150
return getBodyAsString(connectorResponse);
149-
} catch (NullPointerException | IOException e) {
151+
} catch (IOException e) {
150152
}
151153
return null;
152154
}

src/main/java/org/kohsuke/github/connector/GitHubConnectorResponse.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ public String header(String name) {
8686
*
8787
* @return the response body
8888
* @throws IOException
89-
* if an I/O Exception occurs.
89+
* if response stream is null or an I/O Exception occurs.
9090
*/
91+
@Nonnull
9192
public abstract InputStream bodyStream() throws IOException;
9293

9394
/**
@@ -121,7 +122,7 @@ public Map<String, List<String>> allHeaders() {
121122
}
122123

123124
/**
124-
* Handles the "Content-Encoding" header.
125+
* Handles wrapping the body stream if indicated by the "Content-Encoding" header.
125126
*
126127
* @param stream
127128
* the stream to possibly wrap
@@ -139,6 +140,24 @@ protected InputStream wrapStream(InputStream stream) throws IOException {
139140
throw new UnsupportedOperationException("Unexpected Content-Encoding: " + encoding);
140141
}
141142

143+
/**
144+
* Parse a header value as a signed decimal integer.
145+
*
146+
* @param name
147+
* the header field to parse
148+
* @return integer value of the header field
149+
* @throws NumberFormatException
150+
* if the header is missing or does not contain a parsable integer.
151+
*/
152+
public final int parseInt(String name) throws NumberFormatException {
153+
try {
154+
String headerValue = header(name);
155+
return Integer.parseInt(headerValue);
156+
} catch (NumberFormatException e) {
157+
throw new NumberFormatException(name + ": " + e.getMessage());
158+
}
159+
}
160+
142161
public abstract static class ByteArrayResponse extends GitHubConnectorResponse {
143162

144163
private boolean inputStreamRead = false;
@@ -155,6 +174,7 @@ protected ByteArrayResponse(@Nonnull GitHubConnectorRequest request,
155174
* {@inheritDoc}
156175
*/
157176
@Override
177+
@Nonnull
158178
public InputStream bodyStream() throws IOException {
159179
if (isClosed) {
160180
throw new IOException("Response is closed");
@@ -171,7 +191,11 @@ public InputStream bodyStream() throws IOException {
171191
}
172192
}
173193

174-
return inputBytes == null ? null : new ByteArrayInputStream(inputBytes);
194+
if (inputBytes == null) {
195+
throw new IOException("Response body missing, stream null");
196+
}
197+
198+
return new ByteArrayInputStream(inputBytes);
175199
}
176200

177201
/**

src/main/java/org/kohsuke/github/internal/EnumUtils.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ public static <E extends Enum<E>> E getNullableEnumOrDefault(Class<E> enumClass,
4949
*/
5050
public static <E extends Enum<E>> E getEnumOrDefault(Class<E> enumClass, String value, E defaultEnum) {
5151
try {
52-
return Enum.valueOf(enumClass, value.toUpperCase(Locale.ROOT));
53-
} catch (NullPointerException | IllegalArgumentException e) {
54-
LOGGER.warning("Unknown value " + value + " for enum class " + enumClass.getName() + ", defaulting to "
55-
+ defaultEnum.name());
56-
return defaultEnum;
52+
if (value != null) {
53+
return Enum.valueOf(enumClass, value.toUpperCase(Locale.ROOT));
54+
}
55+
} catch (IllegalArgumentException e) {
5756
}
57+
58+
LOGGER.warning("Unknown value " + value + " for enum class " + enumClass.getName() + ", defaulting to "
59+
+ defaultEnum.name());
60+
return defaultEnum;
5861
}
5962

6063
private EnumUtils() {

0 commit comments

Comments
 (0)