Bug 238484 - [1.5][compiler] Eclipse generates bad code (major regression)
Summary: [1.5][compiler] Eclipse generates bad code (major regression)
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 critical with 3 votes (vote)
Target Milestone: 3.4.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 237912 238534 241502 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-06-25 16:37 EDT by Eric Goff CLA
Modified: 2008-08-29 04:40 EDT (History)
10 users (show)

See Also:


Attachments
Proposed patch (15.83 KB, patch)
2008-06-27 12:42 EDT, Philipe Mulet CLA
no flags Details | Diff
Better patch (12.55 KB, patch)
2008-06-27 17:36 EDT, Philipe Mulet CLA
no flags Details | Diff
Patch for 3.3.x (12.55 KB, patch)
2008-06-27 17:39 EDT, Philipe Mulet CLA
no flags Details | Diff
Patch for 3.4.x (13.56 KB, patch)
2008-06-27 19:00 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Goff CLA 2008-06-25 16:37:26 EDT
Build ID: I20080617-2000

Steps To Reproduce:
1.Compile the code on eclipse (no errors)
2. Run the code on a sun java jvm
3. Blammo!  NoSuchMethodError


More information:
The key here, is that I have an interface
that defines a generic method that throws
an Exception.  An abstract class that implements
the interface declares it as method that does not
throw the exception.
This worked fine in 3.3.2

Here is the source:

package mypack;

import java.io.IOException;
interface TreeVisitor<T,U> {
	public T visit(U location) ;
}

interface TreeVisitable<U> {
	public <T> T visit(TreeVisitor<T,U> visitor) throws IOException ;
}

abstract class Param implements TreeVisitable<Param> {
	public final Param lookforParam(final String name) {
		TreeVisitor<Param, Param> visitor = new TreeVisitor<Param, Param>() {
			public Param visit(Param location) {
				return null ;
			}
		};
		return visit(visitor) ;
	}
	public abstract <T> T visit(TreeVisitor<T, Param> visitor);
}

class StructParam extends Param {
	public <T> T visit(TreeVisitor<T, Param> visitor) {
		return null ;
	}
}
public class Main {
	public static void main(String[] args) {
		StructParam p = new StructParam() ;
		p.lookforParam("abc") ;
		System.out.println("done") ;
	}

}
Comment 1 Eric Goff CLA 2008-06-25 16:39:39 EDT
I should mention that when I use the Sun compiler,
all works as expected.
Comment 2 Eric Goff CLA 2008-06-25 16:47:18 EDT
If I remove the abstract method declaration of "visit" from "Param",
all works well.

Although that is a workaround, the fact you are generating code errors
that are not caught until *very* well into the runtime
is cause for extreme concern IMHO.
Comment 3 Nitin Dahyabhai CLA 2008-06-25 17:02:46 EDT
Which JRE are you compiling against and which version are you trying to run the code with?  Which method call is throwing the NoSuchMethodError (or even just what's on that line)?
Comment 4 Eric Goff CLA 2008-06-25 17:16:04 EDT
Ah sorry, on eclipse I am generating code with a 1.5 compiler compliance level.

For runtime:
root@egoff:~# java -version
java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

For compilation:
root@build:/# java -version
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Server VM (build 1.6.0_03-b05, mixed mode)

Eclipse 3.3.2, and the 2 versions of sun java play nicely with each other.

Eclipse 3.4.0 is the monkey wrench.
Comment 5 Eric Goff CLA 2008-06-25 17:18:16 EDT
root@egoff:~# java -cp /tmp/foo.jar mypack.Main
Exception in thread "main" java.lang.NoSuchMethodError: mypack.Param.visit(Lmypack/TreeVisitor;)Lmypack/Param;
	at mypack.Param.lookforParam(Main.java:19)
	at mypack.Main.main(Main.java:32)
Comment 6 Eric Goff CLA 2008-06-25 19:50:21 EDT
If I remove the "throws IOException" on visit, the program works ok.
Comment 7 Jerome Lanneluc CLA 2008-06-26 04:31:23 EDT
Reproduced with 3.4
Comment 8 Philipe Mulet CLA 2008-06-26 04:47:02 EDT
Regression got introduced during 3.4M7
Comment 9 Philipe Mulet CLA 2008-06-26 04:57:19 EDT
Suspect this is related to fix for bug 79798
Comment 10 Philipe Mulet CLA 2008-06-26 05:22:25 EDT
In presence of "throws IOException", the generated bytecode for method #lookforParam(...) contains invalid method reference:
    11  invokevirtual Param.visit(TreeVisitor) : Param [23]
instead of:
    11  invokevirtual Param.visit(TreeVisitor) : Object [23]

(return type did not get erased properly)

Comment 11 Philipe Mulet CLA 2008-06-26 07:21:28 EDT
The change for bug 79798 is indeed causing grief.
1. It shouldn't create a pseudo method when the most specific exception list is no different from one of the candidate method. This would address the specific scenario of this bug.

2. Moreover, it should NOT create a vanilla MethodBinding, but clone a candidate method binding to preserve the binding semantics, such as erasure etc...
Comment 12 Philipe Mulet CLA 2008-06-27 12:42:34 EDT
Created attachment 106030 [details]
Proposed patch

need to test this patch more
Comment 13 Philipe Mulet CLA 2008-06-27 13:17:07 EDT
Need to backport to 3.4 and 3.3 streams.
Comment 14 Philipe Mulet CLA 2008-06-27 13:18:29 EDT
Added GenericTypeTest#test135-1353
Comment 15 Philipe Mulet CLA 2008-06-27 17:36:13 EDT
Created attachment 106050 [details]
Better patch

Just renamed LessExceptionMethodBinding into MostSpecificExceptionMethodBinding
Comment 16 Philipe Mulet CLA 2008-06-27 17:39:57 EDT
Created attachment 106052 [details]
Patch for 3.3.x
Comment 17 Philipe Mulet CLA 2008-06-27 17:42:49 EDT
Released for 3.5M1
Comment 18 Philipe Mulet CLA 2008-06-27 18:30:42 EDT
Released in 3.3.x maintenance branch
Comment 19 Remy Suen CLA 2008-06-27 18:36:40 EDT
(In reply to comment #13)
> Need to backport to 3.4 and 3.3 streams.
(In reply to comment #16)
> Created an attachment (id=106052) [details]
> Patch for 3.3.x
(In reply to comment #18)
> Released in 3.3.x maintenance branch

Isn't 3.3.x closed?
Comment 20 Eric Goff CLA 2008-06-27 18:46:40 EDT
I dont know your structure, but if people are downloading
3.3.x then they are downloading a product that does not
generate correct java bytecode.
Comment 21 Remy Suen CLA 2008-06-27 18:47:47 EDT
(In reply to comment #0)
> This worked fine in 3.3.2
(In reply to comment #20)
> I dont know your structure, but if people are downloading
> 3.3.x then they are downloading a product that does not
> generate correct java bytecode.

I thought 3.3.x was fine...?
Comment 22 Eric Goff CLA 2008-06-27 18:55:14 EDT
sorry, I knew mistake to response.  :)
You are quite right, 3.3.2 did not exhibit the behavior
I mentioned, Philip might have found something else.
Comment 23 Philipe Mulet CLA 2008-06-27 19:00:25 EDT
Created attachment 106055 [details]
Patch for 3.4.x
Comment 24 Philipe Mulet CLA 2008-06-27 19:10:03 EDT
In 3.3.x stream, last official delivery is 3.3.2, which did not have the problem. However, we do provide backport some hot fixes to 3.3.x stream which are then posted on JDT/Core update area (http://www.eclipse.org/jdt/core/r3.3/index.php#UPDATES) when users are asking for it. Given we backported to 3.3.x stream the fix for bug 79798, we need to backport fix for bug 238484, so as not to let this regression show up there as well.

I will also contribute this fix to 3.4.1, and release it for integration for 3.5M1.

Eric - you can take the first 3.4.1 integration build to get the fix if you want (we shall resume building these next week or so). If it did last too long before materializing, we may want to post you a separate patch to apply to 3.4.0.

Let me know your preference.
Comment 25 Eric Goff CLA 2008-06-27 19:27:32 EDT
I can try 3.4.1 when it comes out.
thank you
Comment 26 Philipe Mulet CLA 2008-06-27 19:31:21 EDT
Released for 3.4.1.
Fixed
Comment 27 Philipe Mulet CLA 2008-06-30 03:47:41 EDT
*** Bug 237912 has been marked as a duplicate of this bug. ***
Comment 28 David Audel CLA 2008-07-16 05:11:10 EDT
*** Bug 238534 has been marked as a duplicate of this bug. ***
Comment 29 Kent Johnson CLA 2008-07-21 10:31:33 EDT
*** Bug 241502 has been marked as a duplicate of this bug. ***
Comment 30 Olivier Thomann CLA 2008-08-06 14:30:40 EDT
Verified for 3.5M1 using I20080805-1307
Comment 31 Jerome Lanneluc CLA 2008-08-29 04:40:25 EDT
Verified for 3.4.1 using M20080827-2000