Bug 125254 - java.util.Arrays.Sort() crashes with AbstractMethodError when compiled using JDT, but works OK when compiled with ant
Summary: java.util.Arrays.Sort() crashes with AbstractMethodError when compiled using ...
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-25 16:21 EST by Paul Hamer CLA
Modified: 2006-01-26 10:54 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Hamer CLA 2006-01-25 16:21:18 EST
I'm using Tomcat 5.5.15, which uses JDT 3.1 (if I'm correctly informed).

I've got the following awfully simple JSP:
---------------------------------------------
<%@ page import="java.util.Arrays,java.util.Comparator" %>
<%
  MyClass[] list = new MyClass[2];
  list[0] = new MyClass();
  list[1] = new MyClass();
  Arrays.sort(list,new Comparator<MyClass>()
            {
              public int compare(MyClass mo1, MyClass mo2)
              {
                return -1; // whatever
              }
            });
%>
<%!
  public class MyClass
  {
    String text = "blah";
    public String getText() { return text; }
  }
%>
---------------------------------------------
It compiles fine, but when executed it crashes like this:

java.lang.AbstractMethodError: org.apache.jsp.error_jsp$1.compare
(Ljava/lang/Object;Ljava/lang/Object;)I
	at java.util.Arrays.mergeSort(Arrays.java:1284)
	at java.util.Arrays.sort(Arrays.java:1223)
	at org.apache.jsp.error_jsp._jspService(org.apache.jsp.error_jsp:64)
        ...more...

At first I thought it's a JDK error, but when I replace Tomcat's jasper-
compiler-jdt.jar by an Ant-compiler jar, the code runs fine !!

The above code also runs fine when I replace "MyClass" by "Object" in the 
Comparator definition, but this is ofcourse not what Java 5 is about :-)

I've already updated to Suns latest JDK 1.5.0_06, but that didn't change anything.

Of course I've correctly instructed Tomcat to support Java 1.5 code. All my other JSPs are stuffed with Java 1.5 specific code and compile/run fine.

I first reported this bug to the Tomcat people, but they told me to file the bug here as it appears to be a JDT bug.
See: http://issues.apache.org/bugzilla/show_bug.cgi?id=38389

This bug already existed in Tomcat 5.5.12, but I don't know which JDT-version it used.

Any clues? Tanx!
Comment 1 Olivier Thomann CLA 2006-01-25 16:33:30 EST
Could you please provide steps to debug the code within Tomcat?
I tried to reproduce inside a compilation unit and I could not.

Thanks.
Comment 2 Olivier Thomann CLA 2006-01-25 22:19:03 EST
The problem comes from the fact that the bridge method is missing in the anonymous class corresponding to the new Comparator<MyClass> { ... }.
I tried to reproduce outside of Tomcat unsuccessfully.
I will continue to investigate to understand the cause of the failure.
Comment 3 Olivier Thomann CLA 2006-01-25 23:22:41 EST
The problem comes from the way the org.apache.jasper.compiler.JDTCompiler is defined.
It sets the compiler options, but it forgot to set the compliance.
I patched the org/apache/jasper/compiler/JDTCompiler.class in jasper-compiler.jar by adding the following line:

        settings.put(CompilerOptions.OPTION_Compliance,
                CompilerOptions.VERSION_1_5);

After the target and the source options have been set. If you consider that Tomcat is always running as a 1.5 compiler with 1.5 libraries, you might always want to set the compliance value to 1.5. If you want to compile 1.4 code using 1.4 libraries, then you might want to set the compliance according to the values of the source and the target platform.

With this patch, I could run the jsp that you provided. So the problem is not directly coming from the jdt compiler. It comes from the way the compiler is called in org.apache.jasper.compiler.JDTCompiler. The options passed to the compiler are incomplete.
Comment 4 Peter Rossbach CLA 2006-01-26 02:08:22 EST
I have fix it,

Many thanks to find this
Peter
Comment 5 Philipe Mulet CLA 2006-01-26 08:55:44 EST
I wonder if we shouldn't be smarter, and notice incompatible compliance (1.4) and source level (1.5); like we do in batch mode.
Comment 6 Olivier Thomann CLA 2006-01-26 10:54:03 EST
Closing as INVALID.
Fix was done in Tomcat source code to set the compliance.