diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java
index f2afaa1b66e0..88d41ed78a4d 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java
@@ -1061,10 +1061,13 @@ public class HighlightMethodUtil {
if (otherSuperReturnType == null || currentType == null || otherSuperReturnType.equals(currentType)) continue;
if (PsiUtil.isLanguageLevel5OrHigher(currentMethod)) {
- if (otherSuperReturnType.isAssignableFrom(currentType)) continue;
- if (currentType.isAssignableFrom(otherSuperReturnType)) {
- returnTypeSubstitutable = otherSuperSignature;
- continue;
+ //http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.4.8 Example 8.1.5-3
+ if (!(otherSuperReturnType instanceof PsiPrimitiveType || currentType instanceof PsiPrimitiveType)) {
+ if (otherSuperReturnType.isAssignableFrom(currentType)) continue;
+ if (currentType.isAssignableFrom(otherSuperReturnType)) {
+ returnTypeSubstitutable = otherSuperSignature;
+ continue;
+ }
}
}
return createIncompatibleReturnTypeMessage(currentMethod, currentMethod, otherSuperMethod, false, otherSuperReturnType,
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/MethodReturnTypeSubstitutability.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/MethodReturnTypeSubstitutability.java
new file mode 100644
index 000000000000..0a31f060d752
--- /dev/null
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/MethodReturnTypeSubstitutability.java
@@ -0,0 +1,17 @@
+
+interface X4 { Integer m(); }
+interface Y4 { Number m(); }
+interface Z4 extends X4, Y4 {}
+
+interface X1 { long m(); }
+interface Y1 { Number m(); }
+interface Z1 extends X1, Y1 {}
+
+interface X2 { long m(); }
+interface Y2 { int m(); }
+interface Z2 extends X2, Y2 {}
+
+interface X3 { String m(); }
+interface Y3 { Integer m(); }
+interface Z3 extends X3, Y3 {}
+
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java
index 02de38b62f5e..0e400c19cb0e 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java
@@ -58,4 +58,5 @@ public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase {
}
public void testJavacQuirks() throws Exception { setLanguageLevel(LanguageLevel.JDK_1_6); doTest(true, false); }
+ public void testMethodReturnTypeSubstitutability() throws Exception { setLanguageLevel(LanguageLevel.JDK_1_6); doTest(true, false); }
}