Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add null check to MP Server.Builder.config() (#5363) #5372

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 @@ -352,7 +352,7 @@ public static ConfigSource create(io.helidon.config.spi.ConfigSource helidonConf
* @return a new MicroProfile Config config source
*/
public static ConfigSource create(Config config) {
return new MpHelidonConfigSource(config);
return new MpHelidonConfigSource(Objects.requireNonNull(config, "Config cannot be null"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import io.helidon.config.Config;
import io.helidon.config.ConfigException;
import io.helidon.config.ConfigSources;
import io.helidon.config.PropertiesConfigParser;
Expand All @@ -36,6 +37,7 @@
import io.helidon.config.spi.ParsableSource;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
Expand Down Expand Up @@ -99,6 +101,12 @@ void testHelidonLazy() {
assertThat("exists called exactly once", lazy.exists.get(), is(1));
}

@Test
void testMpConfigSourcesNullConfig() {
NullPointerException npe = assertThrows(NullPointerException.class, () -> MpConfigSources.create((Config) null));
assertThat(npe.getMessage(), is("Config cannot be null"));
}

private static final class NodeImpl implements ConfigSource, NodeConfigSource {
private static final String DESCRIPTION = "node-unit-test";
private static final String KEY = "key";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;
import java.util.logging.Logger;
Expand Down Expand Up @@ -326,7 +327,7 @@ public Builder port(int port) {
public Builder config(io.helidon.config.Config config) {
this.config = ConfigProviderResolver.instance()
.getBuilder()
.withSources(MpConfigSources.create(config))
.withSources(MpConfigSources.create(Objects.requireNonNull(config, "Config cannot be null")))
.build();

return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021 Oracle and/or its affiliates.
* Copyright (c) 2018, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
import java.util.concurrent.ExecutorService;

import io.helidon.common.configurable.ThreadPoolSupplier;
import io.helidon.config.Config;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
Expand All @@ -30,7 +31,9 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;

Expand Down Expand Up @@ -108,6 +111,12 @@ void testTwoApps() {
}
}

@Test
void testServerNullConfig() {
NullPointerException npe = assertThrows(NullPointerException.class, () -> Server.builder().config((Config) null).build());
assertThat(npe.getMessage(), is("Config cannot be null"));
}

private final class TestApplication1 extends Application {
@Override
public Set<Object> getSingletons() {
Expand Down