diff --git a/src/main/java/uk/org/lidalia/slf4jtest/LoggingEvent.java b/src/main/java/uk/org/lidalia/slf4jtest/LoggingEvent.java index 372aa704..49bdf7c6 100644 --- a/src/main/java/uk/org/lidalia/slf4jtest/LoggingEvent.java +++ b/src/main/java/uk/org/lidalia/slf4jtest/LoggingEvent.java @@ -324,7 +324,7 @@ private LoggingEvent( this.mdc = ImmutableMap.copyOf(mdc); this.marker = checkNotNull(marker); this.throwable = checkNotNull(throwable); - this.message = checkNotNull(message); + this.message = message; this.arguments = from(asList(arguments)).transform(TO_NON_NULL_VALUE).toList(); } @@ -339,7 +339,7 @@ public Object apply(final Object input) { @Identity private final ImmutableMap mdc; @Identity private final Optional marker; @Identity private final Optional throwable; - @Identity private final String message; + @Identity /* @Nullable */ private final String message; @Identity private final ImmutableList arguments; private final Optional creatingLogger; diff --git a/src/test/java/uk/org/lidalia/slf4jtest/LoggingEventTests.java b/src/test/java/uk/org/lidalia/slf4jtest/LoggingEventTests.java index d08e97fc..f297086c 100644 --- a/src/test/java/uk/org/lidalia/slf4jtest/LoggingEventTests.java +++ b/src/test/java/uk/org/lidalia/slf4jtest/LoggingEventTests.java @@ -27,6 +27,7 @@ import static java.util.Arrays.asList; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; +import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; @@ -528,6 +529,12 @@ public void nullArgument() { assertThat(event, is(new LoggingEvent(level, "message with null arg", absent(), absent()))); } + @Test + public void nullMessage() { + LoggingEvent event = new LoggingEvent(level, null); + assertThat(event.getMessage(), nullValue()); + } + @After public void reset() { TestLoggerFactory.reset();