java教程

IllegalArgumentException: Initial capacity must be at least one but was 0

位置:首页 > java教程 > java技巧,2019-03-18 10:33
今天发现tomcat 日记有一个异常 java.lang.IllegalArgumentException: Initial capacity must be at least one but was 0,下面是解决这个问题的方法

java.lang.IllegalArgumentException: Initial capacity must be at least one but was 0问题,还是比较少见的,网上也找了很多解决方法,下面是解决过程。

0

I'm facing issue with log4j2

below is my log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Appenders>
        <Console name="STDOUT" target="SYSTEM_OUT">
            <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="com.opensymphony.xwork2" level="info"/>
        <Logger name="org.apache.struts2" level="info"/>
        <Root level="info">
            <AppenderRef ref="STDOUT"/>
        </Root>
    </Loggers>
</Configuration>

below is the exception

<Jun 21, 2018 7:23:48 PM IST> <Error> <HTTP> <BEA-101165> <Could not load user defined filter in web.xml: org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.
java.lang.ExceptionInInitializerError
        at org.apache.logging.log4j.core.impl.Log4jLogEvent.createContextData(Log4jLogEvent.java:472)
        at org.apache.logging.log4j.core.impl.Log4jLogEvent.<init>(Log4jLogEvent.java:331)
        at org.apache.logging.log4j.core.impl.DefaultLogEventFactory.createEvent(DefaultLogEventFactory.java:54)
        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:401)
        at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.IllegalArgumentException: Initial capacity must be at least one but was 0
        at org.apache.logging.log4j.util.SortedArrayStringMap.<init>(SortedArrayStringMap.java:102)
        at org.apache.logging.log4j.core.impl.ContextDataFactory.createContextData(ContextDataFactory.java:109)
        at org.apache.logging.log4j.core.impl.ContextDataFactory.<clinit>(ContextDataFactory.java:57)
        at org.apache.logging.log4j.core.impl.Log4jLogEvent.createContextData(Log4jLogEvent.java:472)
        at org.apache.logging.log4j.core.impl.Log4jLogEvent.<init>(Log4jLogEvent.java:331)
        Truncated. see log file for complete stacktrace
>

above exception resulting to failure of war file deployment.

below are the jars used

1.commons-fileupload-1.3.3.jar
2.commons-io-2.5.jar
3.commons-lang3-3.6.jar
4.commons-logging-1.1.3.jar
5.freemarker-2.3.26-incubating.jar
6.javassist-3.20.0-GA.jar
7.log4j-1.2-api-2.11.0.jar
8.log4j-api-2.10.0.jar
9.log4j-core-2.11.0.jar
10.ognl-3.1.15.jar
11.struts2-core-2.5.16.jar

what do i need to correct?

1

Try upgrading log4j-api-2.10.0.jar to 2.11.0.

IllegalArgumentException is thrown from the constructor of org.apache.logging.log4j.util.SortedArrayStringMap:

public SortedArrayStringMap(final int initialCapacity) {
    if (initialCapacity < 1) {
        throw new IllegalArgumentException("Initial capacity must be at least one but was " + initialCapacity);
    }
    threshold = ceilingNextPowerOfTwo(initialCapacity);
}

and the given parameter initialCapacity has been changed since 2.11 as follows:

如果看不懂上面的没关系,重点是这

Try upgrading log4j-api-2.10.0.jar to 2.11.0.

中立意思就是把og4j-api-2.10.0.jar 升级到 2.11.0.。但网上没找到2.11.0.的jar包,只在官网上找到了2.11.2的jar,升级后也解决了问题

上面就是IllegalArgumentException: Initial capacity must be at least one but was 0的解决方法。

TAGS:IllegalArgumentExceptionmust be at least one but

猜你喜欢

NewHot