Add tests regarding array accesses

This commit is contained in:
Juan Martín Sotuyo Dodero
2024-08-18 19:40:51 -03:00
parent 33e7e71bfa
commit 4352b53aec

View File

@ -619,6 +619,51 @@ public class GuardLogStatementTest {
this
);
}
}
]]></code>
</test-code>
<test-code>
<description>#5153 array access to constants do not require guards</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class GuardLogStatementTest {
private static final Logger LOG = LogManager.getLogger(GuardLogStatementTest.class);
private final String[] foo = { "foo" };
public void test() {
LOG.info(
"Some message here : foo={}",
foo[0]
);
}
}
]]></code>
</test-code>
<test-code>
<description>#5153 array access to method returned values require guards</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class GuardLogStatementTest {
private static final Logger LOG = LogManager.getLogger(GuardLogStatementTest.class);
public void test() {
LOG.info(
"Some message here : foo={}",
foo()[0]
);
}
private String[] foo() {
return new String[] { "foo" };
}
}
]]></code>
</test-code>