Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
None
-
None
-
None
Description
When I try to upgrade sl4j-api from 1.7.25 to version 1.8.X and 2.X. The following code breaks.
public class TestSl4j extends AbstractTest4StdOut { @Test public void demo() throws Exception{ final Logger logger = LoggerFactory.getLogger(TestSl4j.class); // Log in Main Thread logger.info("Log in main!"); assertEquals("[] {} - Log in main!", getLogAndClear()); } } public abstract class AbstractTest4StdOut { @Rule public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); protected static final long START_TIME_STAMP = System.currentTimeMillis(); protected String getLogAndClear() { System.out.flush(); final String out = systemOutRule.getLog(); systemOutRule.clearLog(); final int idx = out.indexOf('\n'); return out.substring(idx + 1, out.length() - 1); // trim first line and last '\n' } }
The code should pass, but it throws an error:
[ERROR] demo(TestSl4j) Time elapsed: 0.018 s <<< ERROR!
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at demo(TestSl4j.java:19)