diff --git a/src/main/java/com/metamx/common/logger/Logger.java b/src/main/java/com/metamx/common/logger/Logger.java index af526760..5a5d1cba 100644 --- a/src/main/java/com/metamx/common/logger/Logger.java +++ b/src/main/java/com/metamx/common/logger/Logger.java @@ -110,6 +110,9 @@ public void wtf(Throwable t, String message, Object... formatArgs) private String safeFormat(String message, Object... formatArgs) { + if(formatArgs == null || formatArgs.length == 0) { + return message; + } try { return String.format(message, formatArgs); } diff --git a/src/test/java/com/metamx/common/logger/LoggerTest.java b/src/test/java/com/metamx/common/logger/LoggerTest.java new file mode 100644 index 00000000..c095ad99 --- /dev/null +++ b/src/test/java/com/metamx/common/logger/LoggerTest.java @@ -0,0 +1,29 @@ +/* + * Copyright 2015 Metamarkets Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.metamx.common.logger; + +import org.junit.Test; + +public class LoggerTest +{ + @Test + public void testLogWithCrazyMessages() + { + final String message = "this % might %d kill %*.s the %s parser"; + final Logger log = new Logger(LoggerTest.class); + log.warn(message); + } +}