Skip to content

Commit dfab645

Browse files
Merge pull request #2139 from microsoft/dependabot/gradle/com.github.spotbugs-6.5.9
chore(deps): bump com.github.spotbugs from 6.5.8 to 6.5.9
2 parents 9875ed7 + c81311f commit dfab645

14 files changed

Lines changed: 125 additions & 36 deletions

File tree

components/abstractions/src/test/java/com/microsoft/kiota/MultiPartBodyTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,25 @@
1212
import org.junit.jupiter.api.Test;
1313

1414
class MultiPartBodyTest {
15+
private static <T> T nullValue() {
16+
return java.util.Collections.<String, T>emptyMap().get("missing");
17+
}
18+
1519
@Test
1620
void defensive() {
1721
final MultipartBody multipartBody = new MultipartBody();
1822
assertThrows(
1923
IllegalArgumentException.class,
20-
() -> multipartBody.addOrReplacePart(null, "foo", "bar"));
24+
() -> multipartBody.addOrReplacePart(nullValue(), "foo", "bar"));
2125
assertThrows(
2226
IllegalArgumentException.class,
23-
() -> multipartBody.addOrReplacePart("foo", null, "bar"));
27+
() -> multipartBody.addOrReplacePart("foo", nullValue(), "bar"));
2428
assertThrows(
2529
NullPointerException.class,
26-
() -> multipartBody.addOrReplacePart("foo", "bar", null));
27-
assertThrows(IllegalArgumentException.class, () -> multipartBody.getPartValue(null));
28-
assertThrows(IllegalArgumentException.class, () -> multipartBody.removePart(null));
29-
assertThrows(NullPointerException.class, () -> multipartBody.serialize(null));
30+
() -> multipartBody.addOrReplacePart("foo", "bar", nullValue()));
31+
assertThrows(IllegalArgumentException.class, () -> multipartBody.getPartValue(nullValue()));
32+
assertThrows(IllegalArgumentException.class, () -> multipartBody.removePart(nullValue()));
33+
assertThrows(NullPointerException.class, () -> multipartBody.serialize(nullValue()));
3034
assertThrows(
3135
UnsupportedOperationException.class, () -> multipartBody.getFieldDeserializers());
3236
}

components/abstractions/src/test/java/com/microsoft/kiota/PeriodAndDurationTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,40 @@
1010
import java.time.temporal.ChronoUnit;
1111

1212
class PeriodAndDurationTest {
13+
private static <T> T nullValue() {
14+
return java.util.Collections.<String, T>emptyMap().get("missing");
15+
}
16+
1317
@Test
1418
void Defensive() {
1519
// Assert
1620
var exception =
17-
assertThrows(NullPointerException.class, () -> PeriodAndDuration.of(null, null));
21+
assertThrows(
22+
NullPointerException.class,
23+
() -> PeriodAndDuration.of(nullValue(), nullValue()));
1824
assertTrue(exception.getMessage().contains("period cannot be null"));
1925

2026
var exception2 =
2127
assertThrows(
2228
NullPointerException.class,
23-
() -> PeriodAndDuration.of(null, Duration.ZERO));
29+
() -> PeriodAndDuration.of(nullValue(), Duration.ZERO));
2430
assertTrue(exception2.getMessage().contains("period cannot be null"));
2531

2632
var exception3 =
2733
assertThrows(
28-
NullPointerException.class, () -> PeriodAndDuration.of(Period.ZERO, null));
34+
NullPointerException.class,
35+
() -> PeriodAndDuration.of(Period.ZERO, nullValue()));
2936
assertTrue(exception3.getMessage().contains("duration cannot be null"));
3037

3138
var exception4 =
32-
assertThrows(NullPointerException.class, () -> PeriodAndDuration.ofDuration(null));
39+
assertThrows(
40+
NullPointerException.class,
41+
() -> PeriodAndDuration.ofDuration(nullValue()));
3342
assertTrue(exception4.getMessage().contains("duration cannot be null"));
3443

3544
var exception5 =
36-
assertThrows(NullPointerException.class, () -> PeriodAndDuration.ofPeriod(null));
45+
assertThrows(
46+
NullPointerException.class, () -> PeriodAndDuration.ofPeriod(nullValue()));
3747
assertTrue(exception5.getMessage().contains("period cannot be null"));
3848

3949
final PeriodAndDuration periodAndDuration =

components/abstractions/src/test/java/com/microsoft/kiota/authentication/ApiKeyAuthenticationProviderTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
import java.util.HashSet;
1111

1212
public class ApiKeyAuthenticationProviderTest {
13+
private static <T> T nullValue() {
14+
return java.util.Collections.<String, T>emptyMap().get("missing");
15+
}
16+
1317
@Test
1418
void DefensivePrograming() {
1519
assertThrows(
@@ -23,7 +27,9 @@ void DefensivePrograming() {
2327

2428
var value =
2529
new ApiKeyAuthenticationProvider("key", "param", ApiKeyLocation.QUERY_PARAMETER);
26-
assertThrows(NullPointerException.class, () -> value.authenticateRequest(null, null));
30+
assertThrows(
31+
NullPointerException.class,
32+
() -> value.authenticateRequest(nullValue(), nullValue()));
2733
}
2834

2935
@Test

components/abstractions/src/test/java/com/microsoft/kiota/serialization/DeserializationHelpersTest.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,45 @@ class DeserializationHelpersTest {
1919
private static final String _jsonContentType = "application/json";
2020
private static final String _charset = "utf-8";
2121

22+
private static <T> T nullValue() {
23+
return java.util.Collections.<String, T>emptyMap().get("missing");
24+
}
25+
26+
private static String nullString() {
27+
return nullValue();
28+
}
29+
30+
private static InputStream nullInputStream() {
31+
return nullValue();
32+
}
33+
34+
private static ParsableFactory<TestEntity> nullFactory() {
35+
return nullValue();
36+
}
37+
2238
@Test
2339
void defensive() {
2440
assertThrows(
2541
NullPointerException.class,
2642
() ->
2743
KiotaSerialization.deserialize(
28-
null,
29-
(InputStream) null,
44+
nullString(),
45+
nullInputStream(),
3046
TestEntity::createFromDiscriminatorValue));
3147
assertThrows(
3248
NullPointerException.class,
3349
() ->
3450
KiotaSerialization.deserialize(
3551
_jsonContentType,
36-
(InputStream) null,
52+
nullInputStream(),
3753
TestEntity::createFromDiscriminatorValue));
3854
assertThrows(
3955
NullPointerException.class,
4056
() ->
4157
KiotaSerialization.deserialize(
4258
_jsonContentType,
4359
new ByteArrayInputStream("{}".getBytes(_charset)),
44-
(ParsableFactory<TestEntity>) null));
60+
nullFactory()));
4561
}
4662

4763
@Test
@@ -50,23 +66,23 @@ void defensiveCollection() {
5066
NullPointerException.class,
5167
() ->
5268
KiotaSerialization.deserializeCollection(
53-
null,
54-
(InputStream) null,
69+
nullString(),
70+
nullInputStream(),
5571
TestEntity::createFromDiscriminatorValue));
5672
assertThrows(
5773
NullPointerException.class,
5874
() ->
5975
KiotaSerialization.deserializeCollection(
6076
_jsonContentType,
61-
(InputStream) null,
77+
nullInputStream(),
6278
TestEntity::createFromDiscriminatorValue));
6379
assertThrows(
6480
NullPointerException.class,
6581
() ->
6682
KiotaSerialization.deserializeCollection(
6783
_jsonContentType,
6884
new ByteArrayInputStream("{}".getBytes(_charset)),
69-
(ParsableFactory<TestEntity>) null));
85+
nullFactory()));
7086
}
7187

7288
@Test

components/abstractions/src/test/java/com/microsoft/kiota/serialization/SerializationHelpersTest.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,42 @@ class SerializationHelpersTest {
2525
private static final String _jsonContentType = "application/json";
2626
private static final String _charset = "utf-8";
2727

28+
private static <T> T nullValue() {
29+
return java.util.Collections.<String, T>emptyMap().get("missing");
30+
}
31+
32+
private static String nullString() {
33+
return nullValue();
34+
}
35+
36+
private static Parsable nullParsable() {
37+
return nullValue();
38+
}
39+
40+
private static Iterable<Parsable> nullParsableCollection() {
41+
return nullValue();
42+
}
43+
2844
@Test
2945
void defensive() {
3046
assertThrows(
3147
NullPointerException.class,
32-
() -> KiotaSerialization.serializeAsStream(null, (Parsable) null));
48+
() -> KiotaSerialization.serializeAsStream(nullString(), nullParsable()));
3349
assertThrows(
3450
NullPointerException.class,
35-
() -> KiotaSerialization.serializeAsStream(_jsonContentType, (Parsable) null));
51+
() -> KiotaSerialization.serializeAsStream(_jsonContentType, nullParsable()));
3652
}
3753

3854
@Test
3955
void defensiveCollection() {
4056
assertThrows(
4157
NullPointerException.class,
42-
() -> KiotaSerialization.serializeAsStream(null, (Iterable<Parsable>) null));
58+
() -> KiotaSerialization.serializeAsStream(nullString(), nullParsableCollection()));
4359
assertThrows(
4460
NullPointerException.class,
4561
() ->
4662
KiotaSerialization.serializeAsStream(
47-
_jsonContentType, (Iterable<Parsable>) null));
63+
_jsonContentType, nullParsableCollection()));
4864
}
4965

5066
@Test

components/abstractions/src/test/java/com/microsoft/kiota/serialization/mocks/TestBackedModelEntity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
104104
put(
105105
"workDuration",
106106
n -> {
107-
setWorkDuration(n.getPeriodAndDurationValue());
107+
final var value = n.getPeriodAndDurationValue();
108+
if (value != null) {
109+
setWorkDuration(value);
110+
}
108111
});
109112
put(
110113
"startWorkTime",

components/abstractions/src/test/java/com/microsoft/kiota/serialization/mocks/TestEntity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
110110
put(
111111
"workDuration",
112112
(n) -> {
113-
setWorkDuration(n.getPeriodAndDurationValue());
113+
final var value = n.getPeriodAndDurationValue();
114+
if (value != null) {
115+
setWorkDuration(value);
116+
}
114117
});
115118
put(
116119
"startWorkTime",

components/bundle/src/test/java/com/microsoft/kiota/bundle/BundleTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010
import org.junit.jupiter.api.Test;
1111

1212
class BundleTests {
13+
private static <T> T nullValue() {
14+
return java.util.Collections.<String, T>emptyMap().get("missing");
15+
}
16+
1317
@Test
1418
void throwsErrorNullAuthenticationProvider() throws Exception {
1519
var exception =
16-
assertThrows(NullPointerException.class, () -> new DefaultRequestAdapter(null));
20+
assertThrows(
21+
NullPointerException.class, () -> new DefaultRequestAdapter(nullValue()));
1722
assertEquals("parameter authenticationProvider cannot be null", exception.getMessage());
1823
}
1924

components/http/okHttp/gradle/dependencies.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dependencies {
66
testImplementation(libs.org.mockito.mockito.core)
77
testImplementation(libs.com.squareup.okhttp3.logging.interceptor)
88
testImplementation(libs.com.squareup.okhttp3.mockwebserver)
9+
testImplementation(libs.io.github.std.uritemplate.std.uritemplate)
910

1011

1112
// This dependency is used internally, and not exposed to consumers on their own compile classpath.

components/http/okHttp/src/test/java/com/microsoft/kiota/http/OkHttpRequestAdapterTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
import java.util.stream.Stream;
5252

5353
public class OkHttpRequestAdapterTest {
54+
private static <T> T nullValue() {
55+
return java.util.Collections.<String, T>emptyMap().get("missing");
56+
}
57+
5458
@ParameterizedTest
5559
@EnumSource(
5660
value = HttpMethod.class,
@@ -618,7 +622,7 @@ public static OkHttpClient getMockClient(final Response response) throws IOExcep
618622
(Answer<Void>)
619623
invocation -> {
620624
Callback callback = invocation.getArgument(0);
621-
callback.onResponse(null, response);
625+
callback.onResponse(nullValue(), response);
622626
return null;
623627
})
624628
.when(remoteCall)

0 commit comments

Comments
 (0)