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

Array out of bounds exception while parsing #3359

Open
jpAtOt opened this issue Nov 27, 2024 · 5 comments
Open

Array out of bounds exception while parsing #3359

jpAtOt opened this issue Nov 27, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@jpAtOt
Copy link

jpAtOt commented Nov 27, 2024

I get this error when I try to parse the file src/main/java/org/owasp/webgoat/webwolf/FileServer.java from Webgoat (https://github.com/WebGoat/WebGoat/releases/tag/v2023.8). The parser throws an array out of bounds exception.

Stack trace:

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
    at org.eclipse.jdt.internal.compiler.ast.ReferenceExpression.sIsMoreSpecific(ReferenceExpression.java:1290) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding.(PolyTypeBinding.java:84) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.Scope.mostSpecificMethodBinding(Scope.java:4609) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.Scope.findDefaultAbstractMethod(Scope.java:1295) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod0(Scope.java:1924) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod(Scope.java:1654) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getMethod(Scope.java:3044) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.MessageSend.findMethodBinding(MessageSend.java:1014) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:835) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:390) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:259) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:661) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:362) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:570) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1503) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1628) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:667) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1240) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:712) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1245) ~[org.eclipse.jdt.core-3.28.0.jar:?]
    at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:868) ~[org.eclipse.jdt.core-3.28.0.jar:?]

Is there some workaround on this?

@srikanth-sankaran
Copy link
Contributor

Giving us an extracted test case that shows the problem will help investigate the problem. If I download a zip from there and import into my plain SDK installation workspace, I get tons of errors.

@Madjosz
Copy link

Madjosz commented Nov 27, 2024

Possibly related to #1419.

@jukzi jukzi added bug Something isn't working needinfo Further information is requested labels Nov 28, 2024
@jpAtOt
Copy link
Author

jpAtOt commented Nov 28, 2024

Giving us an extracted test case that shows the problem will help investigate the problem. If I download a zip from there and import into my plain SDK installation workspace, I get tons of errors.

My apologies! Here's the test case.

import static java.util.Comparator.comparing;
import static org.springframework.http.MediaType.ALL_VALUE;

import jakarta.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.FileTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.TimeZone;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

/** Controller for uploading a file */
@Controller
@Slf4j
public class FileServer {

  private static final DateTimeFormatter dateTimeFormatter =
      DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

  @Value("${webwolf.fileserver.location}")
  private String fileLocation;

  @Value("${server.address}")
  private String server;

  @Value("${server.servlet.context-path}")
  private String contextPath;

  @Value("${server.port}")
  private int port;

  @GetMapping(value = "/files")
  public ModelAndView getFiles(
      HttpServletRequest request, Authentication authentication, TimeZone timezone) {
    String username = (null != authentication) ? authentication.getName() : "anonymous";
    File destinationDir = new File(fileLocation, username);

    ModelAndView modelAndView = new ModelAndView();
    record UploadedFile(String name, String size, String link, String creationTime) {}

    var uploadedFiles = new ArrayList<UploadedFile>();
    File[] files = destinationDir.listFiles(File::isFile);
    return modelAndView;
  }
}

@Madjosz
Copy link

Madjosz commented Nov 28, 2024

I can see the "problematic call" to listFiles(File::isFile) like in the mentioned issue so it is likely that it is indeed the same issue.

Still I cannot reproduce the error on my machine. Can you please give some details on your used Java and Eclipse/eclipse-jdt versions?

@jpAtOt
Copy link
Author

jpAtOt commented Nov 29, 2024

on

I can see the "problematic call" to listFiles(File::isFile) like in the mentioned issue so it is likely that it is indeed the same issue.

Still I cannot reproduce the error on my machine. Can you please give some details on your used Java and Eclipse/eclipse-jdt versions?

I have used Eclipse JDT core 3.39.0 and Java 17.

@jukzi jukzi removed the needinfo Further information is requested label Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants