Community
Participate
Working Groups
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)
Could you please provide the complete test case? Thanks.
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 <<<<<<<<<<<<<<<<<<<
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
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.
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
Also see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5086027 this bug got ack'ed.
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.
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.
Verified for 3.2 RC1 using Build id: I20060413-0010.