eclipse-jdt / eclipse-jdt/eclipse.jdt.core
AIOOBE in ReferenceExpression.sIsMoreSpecific when saving incomplete statement
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
### Issue
Saving/compiling a Java file with the following content leads to an `ArrayIndexOutOfBoundsException`:
```java
import java.io.File;
public class JDTIssue {
private void indexOfOfBounds() {
new File("").listFiles(File::isDirectory)
}
}
```
Note that the statement is incomplete, as the semicolon is missing.
### Initial Analysis
`File::listFiles()` is polymorphic and has two 1-argument implementations that accept either a `FilenameFilter` or a `FileFilter`.
These interfaces look as follows:
```java
public interface FilenameFilter {
boolean accept(File dir, String name);
}
public interface FileFilter {
boolean accept(File pathname);
}
```
While searching for the correct method binding (which in this case is the method accepting a `FileFilter`), the method `ReferenceExpression::sIsMoreSpecific()` is executed with type bindings for the two `accept` methods of `FileNameFilter` and `FileFilter`. It compares the parameter lists of both `accept` methods and fails with an AIOOBE due to different sizes of the parameter lists, although the code should only be reached in case the parameter lists have equal length:
https://github.com/eclipse-jdt/eclipse.jdt.core/blob/816bc73d6b044d55043601b9e3a4e00f08551df4/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java#L1302-L1306
The stack when the exception occurs looks as follows:
```
ReferenceExpression.sIsMoreSpecific(TypeBinding, TypeBinding, Scope) line: 1304
PolyTypeBinding.sIsMoreSpecific(TypeBinding, TypeBinding, Scope) line: 84
MethodScope(Scope).mostSpecificMethodBinding(MethodBinding[], int, TypeBinding[], InvocationSite, ReferenceBinding) line: 4659
MethodScope(Scope).findDefaultAbstractMethod(ReferenceBinding, char[], TypeBinding[], InvocationSite, ReferenceBinding, ObjectVector, MethodBinding[]) line: 1310
MethodScope(Scope).findMethod0(ReferenceBinding, char[], TypeBinding[], InvocationSite, boolean) line: 1938
MethodScope(Scope).findMethod(ReferenceBinding, char[], TypeBinding[], InvocationSite, boolean) line: 1668
MethodScope(Scope).getMethod(TypeBinding, char[], TypeBinding[], InvocationSite) line: 3094
MessageSend.findMethodBinding(BlockScope) line: 1023
MessageSend.resolveType(BlockScope) line: 838
MessageSend(Expression).resolve(BlockScope) line: 1166
MethodDeclaration(AbstractMethodDeclaration).resolveStatements() line: 662
MethodDeclaration.resolveStatements() line: 388
MethodDeclaration(AbstractMethodDeclaration).resolve(ClassScope) line: 571
TypeDeclaration.resolve() line: 1508
TypeDeclaration.resolve(CompilationUnitScope) line: 1633
CompilationUnitDeclaration.resolve() line: 668
CompilationUnitResolver.resolve(CompilationUnitDeclaration, ICompilationUnit, NodeSearcher, boolean, boolean, boolean) line: 1318
CompilationUnitResolver.resolve(ICompilationUnit, IJavaProject, List, NodeSearcher, Map, WorkingCopyOwner, int, IProgressMonitor) line: 790
ASTParser.internalCreateAST(IProgressMonitor) line: 1245
ASTParser.createAST(IProgressMonitor) line: 868
CoreASTProvider$1.run() line: 294
SafeRunner.run(ISafeRunnable) line: 45
CoreASTProvider.createAST(ITypeRoot, IProgressMonitor) line: 286
CoreASTProvider.getAST(ITypeRoot, CoreASTProvider$WAIT_FLAG, IProgressMonitor) line: 199
SharedASTProviderCore.getAST(ITypeRoot, SharedASTProviderCore$WAIT_FLAG, IProgressMonitor) line: 138
SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(ITypeRoot, ITextSelection, IProgressMonitor) line: 166
SelectionListenerWithASTManager$PartListenerGroup$1.run(IProgressMonitor) line: 151
Worker.run() line: 63
```
I can have a look at this issue and provide a PR, but it will take some time until I can address it. So if someone knows that code well and can easily fix this or if you consider this to be more urgent, feel free to take over.
Contributor guide
Assessment
This issue has not been assessed yet.