Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@
import org.junit.jupiter.api.Test;

class MultiPartBodyTest {
private static <T> T nullValue() {
return java.util.Collections.<String, T>emptyMap().get("missing");
}

@Test
void defensive() {
final MultipartBody multipartBody = new MultipartBody();
assertThrows(

Check warning on line 22 in components/abstractions/src/test/java/com/microsoft/kiota/MultiPartBodyTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqToBjZpC81PDJvE&open=AZ9cgqToBjZpC81PDJvE&pullRequest=2139
IllegalArgumentException.class,
() -> multipartBody.addOrReplacePart(null, "foo", "bar"));
() -> multipartBody.addOrReplacePart(nullValue(), "foo", "bar"));
assertThrows(

Check warning on line 25 in components/abstractions/src/test/java/com/microsoft/kiota/MultiPartBodyTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqToBjZpC81PDJvF&open=AZ9cgqToBjZpC81PDJvF&pullRequest=2139
IllegalArgumentException.class,
() -> multipartBody.addOrReplacePart("foo", null, "bar"));
() -> multipartBody.addOrReplacePart("foo", nullValue(), "bar"));
assertThrows(

Check warning on line 28 in components/abstractions/src/test/java/com/microsoft/kiota/MultiPartBodyTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqToBjZpC81PDJvG&open=AZ9cgqToBjZpC81PDJvG&pullRequest=2139
NullPointerException.class,
() -> multipartBody.addOrReplacePart("foo", "bar", null));
assertThrows(IllegalArgumentException.class, () -> multipartBody.getPartValue(null));
assertThrows(IllegalArgumentException.class, () -> multipartBody.removePart(null));
assertThrows(NullPointerException.class, () -> multipartBody.serialize(null));
() -> multipartBody.addOrReplacePart("foo", "bar", nullValue()));
assertThrows(IllegalArgumentException.class, () -> multipartBody.getPartValue(nullValue()));

Check warning on line 31 in components/abstractions/src/test/java/com/microsoft/kiota/MultiPartBodyTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqToBjZpC81PDJvH&open=AZ9cgqToBjZpC81PDJvH&pullRequest=2139
assertThrows(IllegalArgumentException.class, () -> multipartBody.removePart(nullValue()));

Check warning on line 32 in components/abstractions/src/test/java/com/microsoft/kiota/MultiPartBodyTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqToBjZpC81PDJvI&open=AZ9cgqToBjZpC81PDJvI&pullRequest=2139
assertThrows(NullPointerException.class, () -> multipartBody.serialize(nullValue()));

Check warning on line 33 in components/abstractions/src/test/java/com/microsoft/kiota/MultiPartBodyTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqToBjZpC81PDJvJ&open=AZ9cgqToBjZpC81PDJvJ&pullRequest=2139
assertThrows(
UnsupportedOperationException.class, () -> multipartBody.getFieldDeserializers());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,40 @@
import java.time.temporal.ChronoUnit;

class PeriodAndDurationTest {
private static <T> T nullValue() {
return java.util.Collections.<String, T>emptyMap().get("missing");
}

@Test
void Defensive() {
// Assert
var exception =
assertThrows(NullPointerException.class, () -> PeriodAndDuration.of(null, null));
assertThrows(

Check warning on line 21 in components/abstractions/src/test/java/com/microsoft/kiota/PeriodAndDurationTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqVzBjZpC81PDJvK&open=AZ9cgqVzBjZpC81PDJvK&pullRequest=2139
NullPointerException.class,
() -> PeriodAndDuration.of(nullValue(), nullValue()));
assertTrue(exception.getMessage().contains("period cannot be null"));

var exception2 =
assertThrows(

Check warning on line 27 in components/abstractions/src/test/java/com/microsoft/kiota/PeriodAndDurationTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqVzBjZpC81PDJvL&open=AZ9cgqVzBjZpC81PDJvL&pullRequest=2139
NullPointerException.class,
() -> PeriodAndDuration.of(null, Duration.ZERO));
() -> PeriodAndDuration.of(nullValue(), Duration.ZERO));
assertTrue(exception2.getMessage().contains("period cannot be null"));

var exception3 =
assertThrows(

Check warning on line 33 in components/abstractions/src/test/java/com/microsoft/kiota/PeriodAndDurationTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqVzBjZpC81PDJvM&open=AZ9cgqVzBjZpC81PDJvM&pullRequest=2139
NullPointerException.class, () -> PeriodAndDuration.of(Period.ZERO, null));
NullPointerException.class,
() -> PeriodAndDuration.of(Period.ZERO, nullValue()));
assertTrue(exception3.getMessage().contains("duration cannot be null"));

var exception4 =
assertThrows(NullPointerException.class, () -> PeriodAndDuration.ofDuration(null));
assertThrows(

Check warning on line 39 in components/abstractions/src/test/java/com/microsoft/kiota/PeriodAndDurationTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqVzBjZpC81PDJvN&open=AZ9cgqVzBjZpC81PDJvN&pullRequest=2139
NullPointerException.class,
() -> PeriodAndDuration.ofDuration(nullValue()));
assertTrue(exception4.getMessage().contains("duration cannot be null"));

var exception5 =
assertThrows(NullPointerException.class, () -> PeriodAndDuration.ofPeriod(null));
assertThrows(

Check warning on line 45 in components/abstractions/src/test/java/com/microsoft/kiota/PeriodAndDurationTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqVzBjZpC81PDJvO&open=AZ9cgqVzBjZpC81PDJvO&pullRequest=2139
NullPointerException.class, () -> PeriodAndDuration.ofPeriod(nullValue()));
assertTrue(exception5.getMessage().contains("period cannot be null"));

final PeriodAndDuration periodAndDuration =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import java.util.HashSet;

public class ApiKeyAuthenticationProviderTest {
private static <T> T nullValue() {
return java.util.Collections.<String, T>emptyMap().get("missing");
}

@Test
void DefensivePrograming() {
assertThrows(
Expand All @@ -23,7 +27,9 @@

var value =
new ApiKeyAuthenticationProvider("key", "param", ApiKeyLocation.QUERY_PARAMETER);
assertThrows(NullPointerException.class, () -> value.authenticateRequest(null, null));
assertThrows(

Check warning on line 30 in components/abstractions/src/test/java/com/microsoft/kiota/authentication/ApiKeyAuthenticationProviderTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqW-BjZpC81PDJvX&open=AZ9cgqW-BjZpC81PDJvX&pullRequest=2139
NullPointerException.class,
() -> value.authenticateRequest(nullValue(), nullValue()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,70 @@
private static final String _jsonContentType = "application/json";
private static final String _charset = "utf-8";

private static <T> T nullValue() {
return java.util.Collections.<String, T>emptyMap().get("missing");
}

private static String nullString() {
return nullValue();
}

private static InputStream nullInputStream() {
return nullValue();
}

private static ParsableFactory<TestEntity> nullFactory() {
return nullValue();
}

@Test
void defensive() {
assertThrows(

Check warning on line 40 in components/abstractions/src/test/java/com/microsoft/kiota/serialization/DeserializationHelpersTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqWeBjZpC81PDJvP&open=AZ9cgqWeBjZpC81PDJvP&pullRequest=2139
NullPointerException.class,
() ->
KiotaSerialization.deserialize(
null,
(InputStream) null,
nullString(),
nullInputStream(),
TestEntity::createFromDiscriminatorValue));
assertThrows(

Check warning on line 47 in components/abstractions/src/test/java/com/microsoft/kiota/serialization/DeserializationHelpersTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqWeBjZpC81PDJvQ&open=AZ9cgqWeBjZpC81PDJvQ&pullRequest=2139
NullPointerException.class,
() ->
KiotaSerialization.deserialize(
_jsonContentType,
(InputStream) null,
nullInputStream(),
TestEntity::createFromDiscriminatorValue));
assertThrows(
NullPointerException.class,
() ->
KiotaSerialization.deserialize(
_jsonContentType,
new ByteArrayInputStream("{}".getBytes(_charset)),
(ParsableFactory<TestEntity>) null));
nullFactory()));
}

@Test
void defensiveCollection() {
assertThrows(

Check warning on line 65 in components/abstractions/src/test/java/com/microsoft/kiota/serialization/DeserializationHelpersTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqWeBjZpC81PDJvR&open=AZ9cgqWeBjZpC81PDJvR&pullRequest=2139
NullPointerException.class,
() ->
KiotaSerialization.deserializeCollection(
null,
(InputStream) null,
nullString(),
nullInputStream(),
TestEntity::createFromDiscriminatorValue));
assertThrows(

Check warning on line 72 in components/abstractions/src/test/java/com/microsoft/kiota/serialization/DeserializationHelpersTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqWeBjZpC81PDJvS&open=AZ9cgqWeBjZpC81PDJvS&pullRequest=2139
NullPointerException.class,
() ->
KiotaSerialization.deserializeCollection(
_jsonContentType,
(InputStream) null,
nullInputStream(),
TestEntity::createFromDiscriminatorValue));
assertThrows(
NullPointerException.class,
() ->
KiotaSerialization.deserializeCollection(
_jsonContentType,
new ByteArrayInputStream("{}".getBytes(_charset)),
(ParsableFactory<TestEntity>) null));
nullFactory()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,42 @@
private static final String _jsonContentType = "application/json";
private static final String _charset = "utf-8";

private static <T> T nullValue() {
return java.util.Collections.<String, T>emptyMap().get("missing");
}

private static String nullString() {
return nullValue();
}

private static Parsable nullParsable() {
return nullValue();
}

private static Iterable<Parsable> nullParsableCollection() {
return nullValue();
}

@Test
void defensive() {
assertThrows(

Check warning on line 46 in components/abstractions/src/test/java/com/microsoft/kiota/serialization/SerializationHelpersTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqWuBjZpC81PDJvT&open=AZ9cgqWuBjZpC81PDJvT&pullRequest=2139
NullPointerException.class,
() -> KiotaSerialization.serializeAsStream(null, (Parsable) null));
() -> KiotaSerialization.serializeAsStream(nullString(), nullParsable()));
assertThrows(

Check warning on line 49 in components/abstractions/src/test/java/com/microsoft/kiota/serialization/SerializationHelpersTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqWuBjZpC81PDJvU&open=AZ9cgqWuBjZpC81PDJvU&pullRequest=2139
NullPointerException.class,
() -> KiotaSerialization.serializeAsStream(_jsonContentType, (Parsable) null));
() -> KiotaSerialization.serializeAsStream(_jsonContentType, nullParsable()));
}

@Test
void defensiveCollection() {
assertThrows(

Check warning on line 56 in components/abstractions/src/test/java/com/microsoft/kiota/serialization/SerializationHelpersTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqWuBjZpC81PDJvV&open=AZ9cgqWuBjZpC81PDJvV&pullRequest=2139
NullPointerException.class,
() -> KiotaSerialization.serializeAsStream(null, (Iterable<Parsable>) null));
() -> KiotaSerialization.serializeAsStream(nullString(), nullParsableCollection()));
assertThrows(

Check warning on line 59 in components/abstractions/src/test/java/com/microsoft/kiota/serialization/SerializationHelpersTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqWuBjZpC81PDJvW&open=AZ9cgqWuBjZpC81PDJvW&pullRequest=2139
NullPointerException.class,
() ->
KiotaSerialization.serializeAsStream(
_jsonContentType, (Iterable<Parsable>) null));
_jsonContentType, nullParsableCollection()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
put(
"workDuration",
n -> {
setWorkDuration(n.getPeriodAndDurationValue());
final var value = n.getPeriodAndDurationValue();
if (value != null) {
setWorkDuration(value);
}
});
put(
"startWorkTime",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
put(
"workDuration",
(n) -> {
setWorkDuration(n.getPeriodAndDurationValue());
final var value = n.getPeriodAndDurationValue();
if (value != null) {
setWorkDuration(value);
}
});
put(
"startWorkTime",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
import org.junit.jupiter.api.Test;

class BundleTests {
private static <T> T nullValue() {
return java.util.Collections.<String, T>emptyMap().get("missing");
}

@Test
void throwsErrorNullAuthenticationProvider() throws Exception {
var exception =
assertThrows(NullPointerException.class, () -> new DefaultRequestAdapter(null));
assertThrows(

Check warning on line 20 in components/bundle/src/test/java/com/microsoft/kiota/bundle/BundleTests.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ9cgqYUBjZpC81PDJvY&open=AZ9cgqYUBjZpC81PDJvY&pullRequest=2139
NullPointerException.class, () -> new DefaultRequestAdapter(nullValue()));
assertEquals("parameter authenticationProvider cannot be null", exception.getMessage());
}

Expand Down
1 change: 1 addition & 0 deletions components/http/okHttp/gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies {
testImplementation(libs.org.mockito.mockito.core)
testImplementation(libs.com.squareup.okhttp3.logging.interceptor)
testImplementation(libs.com.squareup.okhttp3.mockwebserver)
testImplementation(libs.io.github.std.uritemplate.std.uritemplate)


// This dependency is used internally, and not exposed to consumers on their own compile classpath.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
import java.util.stream.Stream;

public class OkHttpRequestAdapterTest {
private static <T> T nullValue() {
return java.util.Collections.<String, T>emptyMap().get("missing");
}

@ParameterizedTest
@EnumSource(
value = HttpMethod.class,
Expand Down Expand Up @@ -618,7 +622,7 @@ public static OkHttpClient getMockClient(final Response response) throws IOExcep
(Answer<Void>)
invocation -> {
Callback callback = invocation.getArgument(0);
callback.onResponse(null, response);
callback.onResponse(nullValue(), response);
return null;
})
.when(remoteCall)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
put(
"workDuration",
(n) -> {
setWorkDuration(n.getPeriodAndDurationValue());
final var value = n.getPeriodAndDurationValue();
if (value != null) {
setWorkDuration(value);
}
});
put(
"startWorkTime",
Expand All @@ -136,7 +139,10 @@ public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
put(
"deviceNames",
(n) -> {
setDeviceNames(n.getCollectionOfPrimitiveValues(String.class));
final var value = n.getCollectionOfPrimitiveValues(String.class);
if (value != null) {
setDeviceNames(value);
}
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
put(
"workDuration",
(n) -> {
setWorkDuration(n.getPeriodAndDurationValue());
final var value = n.getPeriodAndDurationValue();
if (value != null) {
setWorkDuration(value);
}
});
put(
"startWorkTime",
Expand All @@ -159,7 +162,10 @@ public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
put(
"enumCollection",
(n) -> {
setEnumCollection(n.getCollectionOfEnumValues(MyEnum::forValue));
final var value = n.getCollectionOfEnumValues(MyEnum::forValue);
if (value != null) {
setEnumCollection(value);
}
});
put(
"createdDateTime",
Expand All @@ -169,7 +175,10 @@ public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
put(
"phones",
(n) -> {
setPhones(n.getCollectionOfPrimitiveValues(String.class));
final var value = n.getCollectionOfPrimitiveValues(String.class);
if (value != null) {
setPhones(value);
}
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
put(
"workDuration",
(n) -> {
setWorkDuration(n.getPeriodAndDurationValue());
final var value = n.getPeriodAndDurationValue();
if (value != null) {
setWorkDuration(value);
}
});
put(
"startWorkTime",
Expand All @@ -136,7 +139,10 @@ public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
put(
"deviceNames",
(n) -> {
setDeviceNames(n.getCollectionOfPrimitiveValues(String.class));
final var value = n.getCollectionOfPrimitiveValues(String.class);
if (value != null) {
setDeviceNames(value);
}
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ org-mockito-mockito-core = { group = "org.mockito", name = "mockito-core", versi

[plugins]
com-diffplug-spotless = { id = "com.diffplug.spotless", version = "8.8.0" }
com-github-spotbugs = { id = "com.github.spotbugs", version = "6.5.8" }
com-github-spotbugs = { id = "com.github.spotbugs", version = "6.5.9" }
org-sonarqube = { id = "org.sonarqube", version = "7.3.1.8318" }
Loading