Bug 134645 - [1.5][compiler] Java Compiler throws internal exception..
Summary: [1.5][compiler] Java Compiler throws internal exception..
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.2 RC1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-03 21:45 EDT by Misko Hevery CLA
Modified: 2006-04-13 15:23 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Misko Hevery CLA 2006-04-03 21:45:30 EDT
This is on 3.2M6 (worked fine in 3.2M5)

I think this cuade is the cause:
        throw new DataException("") {
            public boolean isTransient() {
              return false;
            }
          };


I get this error while trying to compile my source code.

Internal compiler error
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.problem.ProblemReporter.genericTypeCannotExtendThrowable(ProblemReporter.java:1696)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:961)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1078)
	at org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression.resolveType(QualifiedAllocationExpression.java:344)
	at org.eclipse.jdt.internal.compiler.ast.Expression.resolveTypeExpecting(Expression.java:903)
	at org.eclipse.jdt.internal.compiler.ast.ThrowStatement.resolve(ThrowStatement.java:64)
	at org.eclipse.jdt.internal.compiler.ast.Block.resolve(Block.java:101)
	at org.eclipse.jdt.internal.compiler.ast.IfStatement.resolve(IfStatement.java:234)
	at org.eclipse.jdt.internal.compiler.ast.Block.resolve(Block.java:101)
	at org.eclipse.jdt.internal.compiler.ast.IfStatement.resolve(IfStatement.java:234)
	at org.eclipse.jdt.internal.compiler.ast.Block.resolve(Block.java:101)
	at org.eclipse.jdt.internal.compiler.ast.IfStatement.resolve(IfStatement.java:234)
	at org.eclipse.jdt.internal.compiler.ast.Block.resolve(Block.java:101)
	at org.eclipse.jdt.internal.compiler.ast.IfStatement.resolve(IfStatement.java:234)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:432)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:179)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:403)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1050)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1097)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:353)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:631)
	at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:448)
	at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:300)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:217)
	at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:264)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:56)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:225)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:148)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:603)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:167)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:201)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:230)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:233)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:252)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:285)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:145)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:208)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:58)
Comment 1 Olivier Thomann CLA 2006-04-03 21:49:37 EDT
Could you please provide the complete test case?
Thanks.
Comment 2 Misko Hevery CLA 2006-04-04 00:48:55 EDT
Here is how to reproduce the error...
(Difference is in <T> of class declaration)

THIS FAILS
>>>>>>>>>>>> Bug124645.java <<<<<<<<<<<<<<<<<<<
public class Bug134645<T> {
    public void bug() throws Exception {
        throw new Exception("Bug134645") {
            @Override
            public String toString() {
                return "Bug134645";
            }
        };
    }
}
>>>>>>>>>>>> Bug124645.java <<<<<<<<<<<<<<<<<<<


THIS IS OK
>>>>>>>>>>>> Bug124645.java <<<<<<<<<<<<<<<<<<<
public class Bug134645 {
    public void bug() throws Exception {
        throw new Exception("Bug134645") {
            @Override
            public String toString() {
                return "Bug134645";
            }
        };
    }
}
>>>>>>>>>>>> Bug124645.java <<<<<<<<<<<<<<<<<<<
Comment 3 Philipe Mulet CLA 2006-04-04 03:44:21 EDT
Error is legite, but reporting did not handle anonymous types.
Fixed reporting, also added support for enabling local type in static method (since no generic enclosing instance then).

e.g. this is OK
public class Bug134645<T> {
    public static void bug() throws Exception {
        throw new Exception("Bug134645") {
            @Override
            public String toString() {
                return "Bug134645";
            }
        };
    }
}

Added GenericTypeTest#test0962-0964
Fixed
Comment 4 Misko Hevery CLA 2006-04-04 13:35:07 EDT
You claim that this is a legit error, but Sun's Javac compiler compiles the file no problem (no errors or warnings). Given that they are kind of a de facto standard, I think eclipse should compile as well, at most give a warning. I have seen many instances where eclipse fails to compile (claims something is an error) while sun's javac compiles fine. This makes eclipse hard to use on large projects where most developers use javac.

I would urge you to reconsider this is a warning not an error.
Comment 5 Philipe Mulet CLA 2006-04-05 07:24:00 EDT
We will not mirror javac bugs. Check their bug database and you will understand what I am talking about. Also javac randomly fixes its bugs with new versions, why do we need to align on a moving target, when this is a proven bug in their implementation ?

fyi, javac build 1.6.0-beta2-b77

D:\>javac Bug134645.java -Xlint
X.java:3: a generic class may not extend java.lang.Throwable
        throw new Exception("Bug134645") {
                  ^
X.java:3: warning: [serial] serializable class <anonymous X$1> has no definition of serialVersionUID
        throw new Exception("Bug134645") {
                                         ^
1 error
1 warning
Comment 6 Philipe Mulet CLA 2006-04-05 07:30:42 EDT
Also see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5086027
this bug got ack'ed.
Comment 7 Philipe Mulet CLA 2006-04-05 07:43:09 EDT
Re: I have seen many instances where eclipse fails to compile (claims something is an error) while sun's javac compiles fine.

Did you report these ? If you found valid issues, we will fix them.
Comment 8 Philipe Mulet CLA 2006-04-05 07:46:30 EDT
To explain the reason of the error, no generic type can inherit from Throwable. It can either directly carry type parameters, or have an enclosing type which does.

If you make the declaring method static, then there is no more connection to an enclosing generic type, and the code will be fine again.
Comment 9 Maxime Daniel CLA 2006-04-13 15:23:02 EDT
Verified for 3.2 RC1 using Build id: I20060413-0010.