When the project is used similarly as follows, the system will report a null pointer exception. This error is only true for the development environment, the simulation environment, and the formal environment.
import org.apache.commons.beanutils.ConvertUtils;public class T {/** * @param args * @author Ken_xu */public static void main(String[] args) {// TODO Auto-generated method stubObject obj = ConvertUtils.convert("1", null);System.out.println(obj);}}
Exception in thread "Main" Java. Lang. nullpointerexception
At org. Apache. commons. beanutils. convertutilsbean. Convert (convertutilsbean. Java: 418)
At org. Apache. commons. beanutils. convertutils. Convert (convertutils. Java: 217)
At T. Main (T. Java: 11)
After source code analysis
Object org. Apache. commons. beanutils. convertutilsbean. Convert (string value, class clazz)
The source code of this method for this class is as follows:
public Object convert(String value, Class clazz) { if (log.isDebugEnabled()) { log.debug("Convert string '" + value + "' to class '" + clazz.getName() + "'"); } Converter converter = lookup(clazz); if (converter == null) { converter = lookup(String.class); } if (log.isTraceEnabled()) { log.trace(" Using converter " + converter); } return (converter.convert(clazz, value)); }
After the analysis, it is deemed that the current project uses log4j implementation and sets the global debug level, leading to an exception.
The solution is as follows:
Add the following code to the log4j. properties configuration file:
# Shielding bug org. Apache. commons. beanutils. convertutilsbean. Convert (string value, class clazz) log4j.logger.org. Apache. commons. beanutils = info