NPE protection for IDEA-117277, but actual NPE already fixed by Anna

This commit is contained in:
Bas Leijdekkers
2013-11-29 18:25:57 +01:00
parent 10641feba7
commit 75beb19b08
4 changed files with 13 additions and 7 deletions
@@ -128,10 +128,7 @@ public class UnnecessaryExplicitNumericCastInspection extends BaseInspection {
return;
}
final PsiType operandType = operand.getType();
if (operandType == null || operandType.equals(castType)) {
return;
}
if (isPrimitiveNumericCastNecessary(expression)) {
if (castType.equals(operandType) || isPrimitiveNumericCastNecessary(expression)) {
return;
}
final PsiTypeElement typeElement = expression.getCastType();
@@ -151,6 +148,9 @@ public class UnnecessaryExplicitNumericCastInspection extends BaseInspection {
return true;
}
final PsiType operandType = operand.getType();
if (operandType == null) {
return true;
}
PsiElement parent = expression.getParent();
while (parent instanceof PsiParenthesizedExpression) {
parent = parent.getParent();
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package com.siyeh.ig.psiutils;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.TypeConversionUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
@@ -148,7 +149,8 @@ public class ClassUtils {
return inSamePackage(fieldClass, fromClass);
}
public static boolean isPrimitiveNumericType(PsiType type) {
@Contract("null -> false")
public static boolean isPrimitiveNumericType(@Nullable PsiType type) {
return primitiveNumericTypes.contains(type);
}
@@ -65,7 +65,7 @@ public class TypeUtils {
return getType(CommonClassNames.JAVA_LANG_STRING, context);
}
public static boolean isNarrowingConversion(PsiType operandType, PsiType castType) {
public static boolean isNarrowingConversion(@NotNull PsiType operandType, @NotNull PsiType castType) {
final Integer operandPrecision = typePrecisions.get(operandType);
final Integer castPrecision = typePrecisions.get(castType);
return operandPrecision.intValue() > castPrecision.intValue();
@@ -63,4 +63,8 @@ public class UnnecessaryExplicitNumericCast {
int i() {
return 10;
}
boolean redundantTypeCast(long l) {
return 0L == (long)l;
}
}