Skip to content

Commit 8944c91

Browse files
NullPointerException during AST-Parsing (eclipse-jdt#4238)
Remove guess work from https://bugs.eclipse.org/405706 and https://bugs.eclipse.org/413958 from the time of 1.7, which seems obsolete in 1.8+ Fixes eclipse-jdt#4235
1 parent 0783609 commit 8944c91

File tree

2 files changed

+89
-39
lines changed
  • org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup
  • org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression

2 files changed

+89
-39
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/Scope.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -428,45 +428,6 @@ public static TypeBinding[] greaterLowerBound(TypeBinding[] types, /*@Nullable*/
428428
}
429429
result[j] = null;
430430
removed ++;
431-
} else if (!jType.isCompatibleWith(iType, scope)) {
432-
// avoid creating unsatisfiable intersection types (see https://bugs.eclipse.org/405706):
433-
if (iType.isParameterizedType() && jType.isParameterizedType()) {
434-
// if the wider of the two types (judged by originals) has type variables
435-
// substitute those with their upper bounds and re-check (see https://bugs.eclipse.org/413958):
436-
ParameterizedTypeBinding wideType, narrowType;
437-
if (iType.original().isCompatibleWith(jType.original(), scope)) {
438-
wideType = (ParameterizedTypeBinding) jType;
439-
narrowType = (ParameterizedTypeBinding) iType;
440-
} else if (jType.original().isCompatibleWith(iType.original(), scope)) {
441-
wideType = (ParameterizedTypeBinding) iType;
442-
narrowType = (ParameterizedTypeBinding) jType;
443-
} else {
444-
continue;
445-
}
446-
if (wideType.arguments == null)
447-
continue; // assume we already have an error here
448-
// Skip the following check if inference variables or CaptureBinding18 are involved,
449-
// hopefully during inference a contradictory glb will simply not produce a solution
450-
// (should essentially be detected beforehand in CaptureBinding18.setUpperBounds()):
451-
if (!narrowType.isProperType(false) || !wideType.isProperType(false))
452-
continue;
453-
int numTypeArgs = wideType.arguments.length;
454-
TypeBinding[] bounds = new TypeBinding[numTypeArgs];
455-
for (int k = 0; k < numTypeArgs; k++) {
456-
TypeBinding argument = wideType.arguments[k];
457-
bounds[k] = argument.isTypeVariable() ? ((TypeVariableBinding)argument).upperBound() : argument;
458-
}
459-
ReferenceBinding wideOriginal = (ReferenceBinding) wideType.original();
460-
TypeBinding substitutedWideType =
461-
environment.createParameterizedType(wideOriginal, bounds, wideOriginal.enclosingType());
462-
// if the narrow type is compatible with the substituted wide type, we keep silent,
463-
// substituting type variables with proper types can still satisfy all constraints,
464-
// otherwise ...
465-
if (!narrowType.isCompatibleWith(substitutedWideType, scope)) {
466-
// ... parameterized types are incompatible due to incompatible type arguments => unsatisfiable
467-
return null;
468-
}
469-
}
470431
}
471432
}
472433
}

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6782,5 +6782,94 @@ <T extends B<?>> void bar(T t) {}
67826782
"""
67836783
});
67846784
}
6785+
public void testGH4235() {
6786+
runConformTest(new String[] {
6787+
"repro/AssertJStubs.java",
6788+
"""
6789+
package repro;
6790+
import java.util.List;
6791+
public class AssertJStubs {
6792+
interface Descriptable<SELF> {}
6793+
interface ExtensionPoints<SELF extends ExtensionPoints<SELF, ACTUAL>, ACTUAL> {}
6794+
6795+
public interface Assert<SELF extends Assert<SELF, ACTUAL>, ACTUAL> extends Descriptable<SELF>, ExtensionPoints<SELF, ACTUAL> { }
6796+
public static abstract class AbstractAssert<SELF extends AbstractAssert<SELF, ACTUAL>, ACTUAL> implements Assert<SELF, ACTUAL> {
6797+
protected ACTUAL actual;
6798+
protected SELF myself;
6799+
}
6800+
interface AssertFactory<T, ASSERT extends Assert<?, ?>> {
6801+
ASSERT createAssert(T actual);
6802+
}
6803+
6804+
public static class FactoryBasedNavigableListAssert<SELF extends FactoryBasedNavigableListAssert<SELF, ACTUAL, ELEMENT, ELEMENT_ASSERT>,
6805+
ACTUAL extends List<? extends ELEMENT>,
6806+
ELEMENT,
6807+
ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
6808+
extends AbstractAssert<SELF, ACTUAL> {
6809+
public boolean isEmpty() { return true; }
6810+
}
6811+
6812+
public static class Assertions {
6813+
public static <ACTUAL extends List<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
6814+
FactoryBasedNavigableListAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(List<? extends ELEMENT> actual,
6815+
AssertFactory<ELEMENT, ELEMENT_ASSERT> assertFactory) {
6816+
return null;
6817+
}
6818+
}
6819+
}
6820+
""",
6821+
"repro/SourceType.java",
6822+
"""
6823+
package repro;
6824+
import java.util.List;
6825+
6826+
public interface SourceType {
6827+
List<TargetType> getTargets();
6828+
}
6829+
""",
6830+
"repro/SourceTypeAssert.java",
6831+
"""
6832+
package repro;
6833+
import java.util.List;
6834+
import repro.AssertJStubs.*;
6835+
6836+
public class SourceTypeAssert extends AbstractAssert<SourceTypeAssert, SourceType> {
6837+
protected SourceTypeAssert(SourceType actual, Class<?> selfType) {
6838+
}
6839+
public final FactoryBasedNavigableListAssert<?, List<? extends TargetType>, TargetType, ? extends AbstractTargetTypeAssert<?>> targets() {
6840+
return Assertions.assertThat(actual.getTargets(), TargetTypeAssert::new);
6841+
}
6842+
public final SourceTypeAssert hasNoTargets() {
6843+
targets().isEmpty();
6844+
return myself;
6845+
}
6846+
}
6847+
""",
6848+
"repro/TargetType.java",
6849+
"""
6850+
package repro;
6851+
public interface TargetType { }
6852+
""",
6853+
"repro/AbstractTargetTypeAssert.java",
6854+
"""
6855+
package repro;
6856+
import repro.AssertJStubs.AbstractAssert;
6857+
6858+
public abstract class AbstractTargetTypeAssert<S extends AbstractTargetTypeAssert<S>> extends AbstractAssert<S, TargetType> {
6859+
protected AbstractTargetTypeAssert(TargetType actual, Class<?> selfType) {
6860+
}
6861+
}
6862+
""",
6863+
"repro/TargetTypeAssert.java",
6864+
"""
6865+
package repro;
6866+
public class TargetTypeAssert extends AbstractTargetTypeAssert<TargetTypeAssert> {
6867+
protected TargetTypeAssert(TargetType actual) {
6868+
super(actual, TargetTypeAssert.class);
6869+
}
6870+
}
6871+
"""
6872+
});
6873+
}
67856874
}
67866875

0 commit comments

Comments
 (0)