Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIOOBE in ReferenceExpression.sIsMoreSpecific when saving incomplete statement #1330

Open
HeikoKlare opened this issue Aug 30, 2023 · 0 comments

Comments

@HeikoKlare
Copy link

Issue

Saving/compiling a Java file with the following content leads to an ArrayIndexOutOfBoundsException:

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:

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:

// Both must have the same number of parameters if we got this far
for (int i = 0; i < sParams.length; i++) {
if (TypeBinding.notEquals(sParams[i], tParams[i]))
return false;
}

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.

ShahzaibIbrahim added a commit to ShahzaibIbrahim/eclipse.jdt.core that referenced this issue Sep 22, 2023
…statement eclipse-jdt#1330

While searching for the correct method binding, the method ReferenceExpression::sIsMoreSpecific() is executed with type bindings for the two accept methods of FileNameFilter and FileFilter.

Fix: Added a check before iterating over the arguments for both message to avoid AIOOBE.

eclipse-jdt#1330
ShahzaibIbrahim added a commit to ShahzaibIbrahim/eclipse.jdt.core that referenced this issue Sep 25, 2023
statement eclipse-jdt#1330

As per findings, JLS 20 removed this iteration as compared to JLS 20,
that why removing this specific code block which checks the parameter
for choosing the most specific functions (see reference §15.13.1)

eclipse-jdt#1330
ShahzaibIbrahim added a commit to ShahzaibIbrahim/eclipse.jdt.core that referenced this issue Sep 27, 2023
jukzi pushed a commit to ShahzaibIbrahim/eclipse.jdt.core that referenced this issue Feb 1, 2024
…statement eclipse-jdt#1330

While searching for the correct method binding, the method ReferenceExpression::sIsMoreSpecific() is executed with type bindings for the two accept methods of FileNameFilter and FileFilter.

Fix: Added a check before iterating over the arguments for both message to avoid AIOOBE.

eclipse-jdt#1330
jukzi pushed a commit to ShahzaibIbrahim/eclipse.jdt.core that referenced this issue Feb 1, 2024
statement eclipse-jdt#1330

As per findings, JLS 20 removed this iteration as compared to JLS 20,
that why removing this specific code block which checks the parameter
for choosing the most specific functions (see reference §15.13.1)

eclipse-jdt#1330
jukzi pushed a commit to ShahzaibIbrahim/eclipse.jdt.core that referenced this issue Feb 1, 2024
jjohnstn added a commit to jjohnstn/www.eclipse.org-eclipse that referenced this issue Apr 26, 2024
akurtakov pushed a commit to eclipse-platform/www.eclipse.org-eclipse that referenced this issue Apr 26, 2024
HeikoKlare added a commit to HeikoKlare/eclipse.jdt.core that referenced this issue Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant