Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit b12d917

Browse files
committed
If the properties file is missed it can use default values; fix NPE that Properties throws
1 parent b9963d6 commit b12d917

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

.mvn/wrapper/maven-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
17+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip
1818
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar

src/main/java/uk/bot_by/aws_lambda/slf4j/LambdaLoggerFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private Properties loadProperties(String configurationFile) {
278278
try (InputStream configurationInputStream = Thread.currentThread().getContextClassLoader()
279279
.getResourceAsStream(configurationFile)) {
280280
properties.load(configurationInputStream);
281-
} catch (IOException e) {
281+
} catch (IOException | NullPointerException e) {
282282
// ignored
283283
}
284284

src/test/java/uk/bot_by/aws_lambda/slf4j/PropertiesTest.java

+24
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,28 @@ void useLoggerProperties() {
305305
"properties-request-id \\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[main\\] thread=1 \\[DEBUG\\] test - debug message[\\n\\r]+"));
306306
}
307307

308+
@DisplayName("Try to read missed logger properties file, use default values")
309+
@Test
310+
void missedProperties() {
311+
// given
312+
var loggerFactory = spy(new LambdaLoggerFactory("missed.properties"));
313+
314+
doReturn(printStream).when(loggerFactory).getPrintStream();
315+
316+
MDC.put("request#", "properties-request-id");
317+
318+
// when
319+
var logger = loggerFactory.getLogger("lambda.logger.test");
320+
321+
logger.debug("debug message");
322+
logger.info("info message");
323+
324+
// then
325+
printStream.flush();
326+
printStream.close();
327+
outputStream.toString(StandardCharsets.UTF_8);
328+
assertThat(outputStream.toString(StandardCharsets.UTF_8), matchesPattern(
329+
"INFO lambda.logger.test - info message[\\n\\r]+"));
330+
}
331+
308332
}

0 commit comments

Comments
 (0)