diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java index 417bdb8d77ee..432df2b39874 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java @@ -557,7 +557,7 @@ public class WeakestTypeFinder { @Nullable private static PsiClass getVisibleInheritor(@NotNull PsiClass superClass, PsiElement context) { final Query search = DirectClassInheritorsSearch.search(superClass, context.getResolveScope()); - Project project = superClass.getProject(); + final Project project = superClass.getProject(); for (PsiClass aClass : search) { if (superClass.isInheritor(aClass, true)) { if (PsiUtil.isAccessible(project, aClass, context, null)) { @@ -576,21 +576,19 @@ public class WeakestTypeFinder { return false; } boolean shouldAdd = true; - for (Iterator iterator = weakestTypeClasses.iterator(); iterator.hasNext(); ) { + for (final Iterator iterator = weakestTypeClasses.iterator(); iterator.hasNext(); ) { final PsiClass weakestTypeClass = iterator.next(); - if (!weakestTypeClass.equals(aClass)) { - if (aClass.isInheritor(weakestTypeClass, true)) { - iterator.remove(); - } - else if (weakestTypeClass.isInheritor(aClass, true)) { - shouldAdd = false; - } - else { - iterator.remove(); - shouldAdd = false; - } + if (weakestTypeClass.equals(aClass)) { + return true; + } + if (aClass.isInheritor(weakestTypeClass, true)) { + iterator.remove(); + } + else if (weakestTypeClass.isInheritor(aClass, true)) { + shouldAdd = false; } else { + iterator.remove(); shouldAdd = false; } } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java index 5f1deee580ca..aeb2e1a5f811 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java @@ -125,4 +125,29 @@ public class TypeMayBeWeakened { if (ref != null) ref.set(value); return ref; } +} +class MyClass { + + public MyClass(java.util.Date date, String[] classNames) {} + + static MyClass readMyClass(final ObjectInputStream objectInput) { + final long time = objectInput.readLong(); + final int size = objectInput.readInt(); + final String[] classNames = new String[size]; + for (int i = 0; i < size; i++) { + classNames[i] = objectInput.readUTF(); + } + return new MyClass(new java.util.Date(time), classNames); + } +} +interface DataInput { + long readLong(); + int readInt(); + String readUTF(); +} +abstract class ObjectInputStream implements DataInput { + + public String readUTF() { + return null; + } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml index 599595a7163a..577f33646869 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml @@ -22,6 +22,13 @@ Type of variable <code>iaex</code> may be weakened to 'java.lang.RuntimeException' + + TypeMayBeWeakened.java + 133 + Type may be weakened + Type of parameter <code>objectInput</code> may be weakened to 'com.siyeh.igtest.abstraction.weaken_type.DataInput' #loc + + AutoClosableTest.java 34