Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 530981

Summary: [newindex] IndexOutOfBoundsException in ClassFileToIndexConverter.addMethod
Product: [Eclipse Project] JDT Reporter: Igor Fedorenko <igor>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: stephan.herrmann
Version: 4.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug
Attachments:
Description Flags
example project that demonstrates the problem none

Description Igor Fedorenko CLA 2018-02-09 23:39:26 EST
Created attachment 272630 [details]
example project that demonstrates the problem

I am getting "An internal error occurred during: "Updating Java index"" error popup and the exception below in eclipse .log file when I import the attached example project and enable the new java index in the workspace preferences:


java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:653)
	at java.util.ArrayList.get(ArrayList.java:429)
	at org.eclipse.jdt.internal.core.nd.indexer.ClassFileToIndexConverter.addMethod(ClassFileToIndexConverter.java:387)
	at org.eclipse.jdt.internal.core.nd.indexer.ClassFileToIndexConverter.addType(ClassFileToIndexConverter.java:219)
	at org.eclipse.jdt.internal.core.nd.indexer.Indexer.addClassToIndex(Indexer.java:850)
	at org.eclipse.jdt.internal.core.nd.indexer.Indexer.addElement(Indexer.java:823)
	at org.eclipse.jdt.internal.core.nd.indexer.Indexer.rescanArchive(Indexer.java:637)
	at org.eclipse.jdt.internal.core.nd.indexer.Indexer.rescan(Indexer.java:284)
	at org.eclipse.jdt.internal.core.nd.indexer.Indexer.lambda$0(Indexer.java:146)
	at org.eclipse.core.runtime.jobs.Job$2.run(Job.java:182)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)


From what I can tell, the problem is caused by slightly malformed lib/test/Borked.class file, which has inconsistent signature and description of borked() method, here is relevant javap output:


  public void borked(java.util.ArrayList<java.lang.Object>);
    descriptor: ()V


The class works at runtime because oracle jvm does not validate method signatures (see [1]), so I expect the indexer to tolerate such classes too.


[1] https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.4
Comment 1 Stephan Herrmann CLA 2018-02-10 08:18:39 EST
Let's look at the full output from javap -p -v -c:

  public void borked(java.util.ArrayList<java.lang.Object>);                                                                             
    descriptor: ()V                                                                                                                      
    flags: ACC_PUBLIC                                                                                                                    
    Code:                                                                                                                                
      stack=0, locals=1, args_size=1                                                                                                     
         0: return                                                                                                                       
      LineNumberTable:                                                                                                                   
        line 4: 0                                                                                                                        
      LocalVariableTable:                                                                                                                
        Start  Length  Slot  Name   Signature                                                                                            
            0       1     0  this   Ltest/Borked;                                                                                        
    Signature: #13                          // (Ljava/util/ArrayList<Ljava/lang/Object;>;)V                                              

The descriptor must be trusted, so you expect us to treat the method as argument-less despite the signature, right?

I'd be surprised, however, if the indexer were the only piece of software that explodes on such byte code.

Out of curiosity: how was the class file produced?
Comment 2 Igor Fedorenko CLA 2018-02-10 09:18:46 EST
(In reply to Stephan Herrmann from comment #1)
> 
> The descriptor must be trusted, so you expect us to treat the method as
> argument-less despite the signature, right?

I expect the new indexer to either use the method descriptor, which is what JVM is using, or skip indexing the method/class as malformed.

> I'd be surprised, however, if the indexer were the only piece of software
> that explodes on such byte code.

Surprisingly enough, exception for the new indexer everything else works without problems, both in development and in production. And it's not just Eclipse, IntelliJ works and so do many command line tools that read/manipulate class files (I work in a large dev org and we use variety of tools).


> Out of curiosity: how was the class file produced?

The attached "Borked" class was creating using ASM library.

In our real codebase the problem is observed in an obfuscated thirdparty library where several of libriry's internal classes have method description/signature mismatch. I don't know if the mismatch is deliberate attempt to confuse decompilers or a bug in the obfuscator.
Comment 3 Eclipse Genie CLA 2020-02-27 18:09:49 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.