fix issues reported by coverity and code style

This commit is contained in:
Skylot 2015-03-09 14:00:59 +03:00
parent 99d831c498
commit 66aa2f8f2a
27 changed files with 64 additions and 62 deletions

View File

@ -10,7 +10,7 @@ public enum ResourceType {
LIB(".so"),
UNKNOWN;
private String[] exts;
private final String[] exts;
ResourceType(String... exts) {
this.exts = exts;

View File

@ -28,7 +28,7 @@ public final class ResourcesLoader {
private static final int READ_BUFFER_SIZE = 8 * 1024;
private static final int LOAD_SIZE_LIMIT = 10 * 1024 * 1024;
private JadxDecompiler jadxRef;
private final JadxDecompiler jadxRef;
ResourcesLoader(JadxDecompiler jadxRef) {
this.jadxRef = jadxRef;

View File

@ -162,10 +162,7 @@ public class ConditionGen extends InsnGen {
if (condition.isCompare()) {
return false;
}
if (condition.getMode() != Mode.NOT) {
return true;
}
return false;
return condition.getMode() != Mode.NOT;
}
private static boolean isArgWrapNeeded(InsnArg arg) {

View File

@ -10,7 +10,7 @@ import java.util.Map;
public class EnumMapAttr implements IAttribute {
public static class KeyValueMap {
private Map<Object, Object> map = new HashMap<Object, Object>();
private final Map<Object, Object> map = new HashMap<Object, Object>();
public Object get(Object key) {
return map.get(key);
@ -21,7 +21,7 @@ public class EnumMapAttr implements IAttribute {
}
}
private Map<FieldNode, KeyValueMap> fieldsMap = new HashMap<FieldNode, KeyValueMap>();
private final Map<FieldNode, KeyValueMap> fieldsMap = new HashMap<FieldNode, KeyValueMap>();
public KeyValueMap getMap(FieldNode field) {
return fieldsMap.get(field);

View File

@ -32,9 +32,9 @@ public class AccessInfo {
}
public AccessInfo getVisibility() {
int f = (accFlags & AccessFlags.ACC_PUBLIC)
| (accFlags & AccessFlags.ACC_PROTECTED)
| (accFlags & AccessFlags.ACC_PRIVATE);
int f = accFlags & AccessFlags.ACC_PUBLIC
| accFlags & AccessFlags.ACC_PROTECTED
| accFlags & AccessFlags.ACC_PRIVATE;
return new AccessInfo(f, type);
}

View File

@ -111,16 +111,9 @@ public final class MethodInfo {
return false;
}
MethodInfo other = (MethodInfo) obj;
if (!shortId.equals(other.shortId)) {
return false;
}
if (!retType.equals(other.retType)) {
return false;
}
if (!declClass.equals(other.declClass)) {
return false;
}
return true;
return shortId.equals(other.shortId)
&& retType.equals(other.retType)
&& declClass.equals(other.declClass);
}
@Override

View File

@ -47,7 +47,7 @@ public final class LiteralArg extends InsnArg {
@Override
public int hashCode() {
return (int) (literal ^ (literal >>> 32)) + 31 * getType().hashCode();
return (int) (literal ^ literal >>> 32) + 31 * getType().hashCode();
}
@Override

View File

@ -1,5 +1,7 @@
package jadx.core.dex.instructions.args;
import org.jetbrains.annotations.NotNull;
public class TypeImmutableArg extends RegisterArg {
private boolean isThis;
@ -36,7 +38,7 @@ public class TypeImmutableArg extends RegisterArg {
}
@Override
void setSVar(SSAVar sVar) {
void setSVar(@NotNull SSAVar sVar) {
if (isThis) {
sVar.setName("this");
}

View File

@ -282,7 +282,7 @@ public class ClassNode extends LineAttrNode implements ILoadable {
field = cn.constFields.get(obj);
}
while (field == null
&& (cn.clsInfo.getParentClass() != null)
&& cn.clsInfo.getParentClass() != null
&& (cn = dex.resolveClass(cn.clsInfo.getParentClass())) != null);
if (field == null && searchGlobal) {

View File

@ -74,7 +74,8 @@ public class InsnNode extends LineAttrNode {
public boolean containsArg(RegisterArg arg) {
for (InsnArg a : arguments) {
if (a == arg || (a.isRegister() && ((RegisterArg) a).getRegNum() == arg.getRegNum())) {
if (a == arg
|| a.isRegister() && ((RegisterArg) a).getRegNum() == arg.getRegNum()) {
return true;
}
}

View File

@ -75,8 +75,8 @@ public class MethodNode extends LineAttrNode implements ILoadable {
this.mthInfo = MethodInfo.fromDex(classNode.dex(), mthData.getMethodIndex());
this.parentClass = classNode;
this.accFlags = new AccessInfo(mthData.getAccessFlags(), AFType.METHOD);
this.noCode = (mthData.getCodeOffset() == 0);
this.methodData = (noCode ? null : mthData);
this.noCode = mthData.getCodeOffset() == 0;
this.methodData = noCode ? null : mthData;
}
@Override
@ -527,7 +527,7 @@ public class MethodNode extends LineAttrNode implements ILoadable {
defaultArgCount = 1;
}
}
result = (argsList == null) || (argsList.size() == defaultArgCount);
result = argsList == null || argsList.size() == defaultArgCount;
}
return result;
}

View File

@ -149,7 +149,7 @@ public class DebugInfoParser {
int adjustedOpcode = c - DBG_FIRST_SPECIAL;
int addrInc = adjustedOpcode / DBG_LINE_RANGE;
addr = addrChange(addr, addrInc, line);
line += DBG_LINE_BASE + (adjustedOpcode % DBG_LINE_RANGE);
line += DBG_LINE_BASE + adjustedOpcode % DBG_LINE_RANGE;
setLine(addr, line);
} else {
throw new DecodeException("Unknown debug insn code: " + c);
@ -263,8 +263,8 @@ public class DebugInfoParser {
int localStart = var.getStartAddr();
int localEnd = var.getEndAddr();
boolean isIntersected = !((localEnd < ssaStart) || (ssaEnd < localStart));
if (isIntersected && (ssaEnd <= localEnd)) {
boolean isIntersected = !(localEnd < ssaStart || ssaEnd < localStart);
if (isIntersected && ssaEnd <= localEnd) {
mergeRequired = true;
}
} else {

View File

@ -210,7 +210,7 @@ public class CodeShrinker extends AbstractVisitor {
// }
SSAVar sVar = arg.getSVar();
// allow inline only one use arg or 'this'
if (sVar == null || (sVar.getVariableUseCount() != 1 && !arg.isThis())) {
if (sVar == null || sVar.getVariableUseCount() != 1 && !arg.isThis()) {
continue;
}
InsnNode assignInsn = sVar.getAssign().getParentInsn();

View File

@ -249,7 +249,7 @@ public class SimplifyVisitor extends AbstractVisitor {
}
InsnNode wrap = ((InsnWrapArg) arg).getWrapInsn();
InsnType wrapType = wrap.getType();
if ((wrapType != InsnType.ARITH && wrapType != InsnType.STR_CONCAT)
if (wrapType != InsnType.ARITH && wrapType != InsnType.STR_CONCAT
|| !wrap.getArg(0).isInsnWrap()) {
return null;
}

View File

@ -194,7 +194,7 @@ public class BlockSplitter extends AbstractVisitor {
private static boolean isDoWhile(Map<Integer, BlockNode> blocksMap, BlockNode curBlock, InsnNode insn) {
// split 'do-while' block (last instruction: 'if', target this block)
if (insn.getType() == InsnType.IF) {
IfNode ifs = (IfNode) (insn);
IfNode ifs = (IfNode) insn;
BlockNode targetBlock = blocksMap.get(ifs.getTarget());
if (targetBlock == curBlock) {
return true;

View File

@ -195,7 +195,7 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
CodeShrinker.shrinkMethod(mth);
if (arrGetInsn.contains(AFlag.WRAPPED)) {
InsnArg wrapArg = BlockUtils.searchWrappedInsnParent(mth, arrGetInsn);
if (wrapArg != null) {
if (wrapArg != null && wrapArg.getParentInsn() != null) {
wrapArg.getParentInsn().replaceArg(wrapArg, iterVar);
} else {
LOG.debug(" checkArrayForEach: Wrapped insn not found: {}, mth: {}", arrGetInsn, mth);
@ -233,7 +233,7 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
RegisterArg iterVar = nextCall.getResult();
if (nextCall.contains(AFlag.WRAPPED)) {
InsnArg wrapArg = BlockUtils.searchWrappedInsnParent(mth, nextCall);
if (wrapArg != null) {
if (wrapArg != null && wrapArg.getParentInsn() != null) {
InsnNode parentInsn = wrapArg.getParentInsn();
if (parentInsn.getType() != InsnType.CHECK_CAST) {
parentInsn.replaceArg(wrapArg, iterVar);

View File

@ -203,7 +203,7 @@ public class RegionMaker {
BlockNode out;
if (loopRegion.isConditionAtEnd()) {
BlockNode thenBlock = condInfo.getThenBlock();
out = (thenBlock == loopStart ? condInfo.getElseBlock() : thenBlock);
out = thenBlock == loopStart ? condInfo.getElseBlock() : thenBlock;
loopStart.remove(AType.LOOP);
loop.getEnd().add(AFlag.SKIP);
stack.addExit(loop.getEnd());
@ -922,13 +922,7 @@ public class RegionMaker {
if (b1 == null || b2 == null) {
return false;
}
if (isReturnBlocks(b1, b2)) {
return true;
}
if (isSyntheticPath(b1, b2)) {
return true;
}
return false;
return isReturnBlocks(b1, b2) || isSyntheticPath(b1, b2);
}
private static boolean isSyntheticPath(BlockNode b1, BlockNode b2) {

View File

@ -103,7 +103,7 @@ public class DebugUtils {
}
for (InsnArg arg : insn.getArguments()) {
if (arg instanceof RegisterArg) {
checkSSAVar(mth, insn, ((RegisterArg) arg));
checkSSAVar(mth, insn, (RegisterArg) arg);
}
}
}
@ -131,7 +131,7 @@ public class DebugUtils {
List<PhiInsn> phis = new ArrayList<PhiInsn>();
for (InsnNode insn : block.getInstructions()) {
if (insn.getType() == InsnType.PHI) {
PhiInsn phi = ((PhiInsn) insn);
PhiInsn phi = (PhiInsn) insn;
phis.add(phi);
if (phi.getArgsCount() != phi.getBlockBinds().size()) {
throw new JadxRuntimeException("Incorrect args and binds in PHI");

View File

@ -189,7 +189,7 @@ public class RegionUtils {
for (IContainer b : r.getSubBlocks()) {
// process try block
CatchAttr cb = b.get(AType.CATCH_BLOCK);
if (cb != null && (b instanceof IRegion)) {
if (cb != null && b instanceof IRegion) {
TryCatchBlock tb = cb.getTryBlock();
for (ExceptionHandler eh : tb.getHandlers()) {
if (isRegionContainsRegion(eh.getHandlerRegion(), region)) {

View File

@ -85,6 +85,9 @@ public class Utils {
}
public static String getStackTrace(Throwable throwable) {
if (throwable == null) {
return "";
}
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
throwable.printStackTrace(pw);
@ -92,6 +95,6 @@ public class Utils {
}
public static int compare(int x, int y) {
return (x < y) ? -1 : ((x == y) ? 0 : 1);
return x < y ? -1 : x == y ? 0 : 1;
}
}

View File

@ -209,7 +209,7 @@ public class BinaryXMLParser extends CommonBinaryParser {
for (int i = 0; i < attributeCount; i++) {
parseAttribute(i);
writer.add('"');
if ((i + 1) < attributeCount) {
if (i + 1 < attributeCount) {
writer.add(" ");
}
}
@ -267,7 +267,7 @@ public class BinaryXMLParser extends CommonBinaryParser {
}
} else {
String str = valuesParser.decodeValue(attrValDataType, attrValData);
writer.add(str);
writer.add(str != null ? str : "null");
}
}

View File

@ -61,7 +61,7 @@ public class CommonBinaryParser extends ParserConstants {
return "";
}
if ((len & 0x80) != 0) {
len = ((len & 0x7F) << 8) | (strArray[start++] & 0xFF);
len = (len & 0x7F) << 8 | strArray[start++] & 0xFF;
}
byte[] arr = Arrays.copyOfRange(strArray, start, start + len);
return new String(arr, ParserStream.STRING_CHARSET_UTF8);

View File

@ -49,9 +49,16 @@ public class ManifestAttributes {
private final Map<String, MAttr> attrMap = new HashMap<String, MAttr>();
public ManifestAttributes() throws Exception {
InputStream xmlStream = ManifestAttributes.class.getResourceAsStream(MANIFEST_ATTR_XML);
DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
doc = dBuilder.parse(xmlStream);
InputStream xmlStream = null;
try {
xmlStream = ManifestAttributes.class.getResourceAsStream(MANIFEST_ATTR_XML);
DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
doc = dBuilder.parse(xmlStream);
} finally {
if (xmlStream != null) {
xmlStream.close();
}
}
}
public void parse() {

View File

@ -150,11 +150,11 @@ public class ParserConstants {
protected static final int ATTR_MANY = ResMakeInternal(9);
private static int ResMakeInternal(int entry) {
return 0x01000000 | (entry & 0xFFFF);
return 0x01000000 | entry & 0xFFFF;
}
protected static boolean isResInternalId(int resid) {
return ((resid & 0xFFFF0000) != 0 && (resid & 0xFF0000) == 0);
return (resid & 0xFFFF0000) != 0 && (resid & 0xFF0000) == 0;
}
// Bit mask of allowed types, for use with ATTR_TYPE.

View File

@ -34,7 +34,7 @@ public class ParserStream {
readPos += 2;
int b1 = input.read();
int b2 = input.read();
return (b2 & 0xFF) << 8 | (b1 & 0xFF);
return (b2 & 0xFF) << 8 | b1 & 0xFF;
}
public int readInt32() throws IOException {
@ -44,7 +44,7 @@ public class ParserStream {
int b2 = in.read();
int b3 = in.read();
int b4 = in.read();
return b4 << 24 | (b3 & 0xFF) << 16 | (b2 & 0xFF) << 8 | (b1 & 0xFF);
return b4 << 24 | (b3 & 0xFF) << 16 | (b2 & 0xFF) << 8 | b1 & 0xFF;
}
public long readUInt32() throws IOException {

View File

@ -113,8 +113,8 @@ public class ValuesParser extends ParserConstants {
}
private String decodeComplex(int data, boolean isFraction) {
double value = (data & (COMPLEX_MANTISSA_MASK << COMPLEX_MANTISSA_SHIFT))
* RADIX_MULTS[(data >> COMPLEX_RADIX_SHIFT) & COMPLEX_RADIX_MASK];
double value = (data & COMPLEX_MANTISSA_MASK << COMPLEX_MANTISSA_SHIFT)
* RADIX_MULTS[data >> COMPLEX_RADIX_SHIFT & COMPLEX_RADIX_MASK];
int unitType = data & COMPLEX_UNIT_MASK;
String unit;
if (isFraction) {

View File

@ -13,6 +13,7 @@ import javax.swing.text.BadLocationException;
import javax.swing.text.Caret;
import javax.swing.text.DefaultCaret;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
@ -135,9 +136,13 @@ class ContentArea extends RSyntaxTextArea {
return;
}
int extentHeight = viewport.getExtentSize().height;
int viewHeight = viewport.getViewSize().height;
Dimension viewSize = viewport.getViewSize();
if (viewSize == null) {
return;
}
int viewHeight = viewSize.height;
int y = Math.max(0, r.y - (extentHeight / 2));
int y = Math.max(0, r.y - extentHeight / 2);
y = Math.min(y, viewHeight - extentHeight);
viewport.setViewPosition(new Point(0, y));