Member variable int type with value 0xff000000 causes processing error
A source code analyzer
Brought to you by:
adangel,
juansotuyo
The following java class causes a NumberFormatException in the RedundantFieldInitializerRule:
public class LinePoint { private int mColor = 0xFF000000; }
The stacktrace is:
Error while processing file: /tmp/LinePoint.java java.lang.NumberFormatException: For input string: "FF000000" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:495) at java.lang.Integer.valueOf(Integer.java:556) at java.lang.Integer.decode(Integer.java:984) at net.sourceforge.pmd.lang.java.rule.optimizations.RedundantFieldInitializerRule.visit(RedundantFieldInitializerRule.java:79) at net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration.jjtAccept(ASTFieldDeclaration.java:23) at net.sourceforge.pmd.lang.java.rule.JavaRuleChainVisitor.visit(JavaRuleChainVisitor.java:40) at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:85) at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:66) at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:122) at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:146) at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:76) at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:43) at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:78) at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:25) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)
The int declaration overflows and would be negative, but it compiles OK and is valid Java code.
Will be fixed with the next version.
Thanks!