FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
A compiler error happens when the provided code is compiled.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program compiles
ACTUAL -
The compiler crashes
ERROR MESSAGES/STACK TRACES THAT OCCUR :
An exception has occurred in the compiler (1.8.0_25). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
at com.sun.tools.javac.code.Scope.includes(Scope.java:296)
at com.sun.tools.javac.comp.Flow$1.trackable(Flow.java:247)
at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.visitVarDef(Flow.java:1832)
at com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitVarDef(Flow.java:2569)
at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scan(Flow.java:1376)
at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.visitLambda(Flow.java:2256)
at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scan(Flow.java:1376)
at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scanExpr(Flow.java:1627)
at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scanExprs(Flow.java:1639)
at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.visitApply(Flow.java:2236)
at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scan(Flow.java:1376)
at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.analyzeTree(Flow.java:2423)
at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.analyzeTree(Flow.java:2406)
at com.sun.tools.javac.comp.Flow.analyzeLambdaThrownTypes(Flow.java:250)
at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2423)
at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
at com.sun.tools.javac.comp.DeferredAttr$2.complete(DeferredAttr.java:284)
at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:245)
at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:232)
at com.sun.tools.javac.comp.Resolve$MethodResultInfo.check(Resolve.java:993)
at com.sun.tools.javac.comp.Resolve$4.checkArg(Resolve.java:826)
at com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.argumentsAcceptable(Resolve.java:731)
at com.sun.tools.javac.comp.Resolve$4.argumentsAcceptable(Resolve.java:835)
at com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:162)
at com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:564)
at com.sun.tools.javac.comp.Resolve.checkMethod(Resolve.java:601)
at com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:3809)
at com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3615)
at com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3522)
at com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3501)
at com.sun.tools.javac.comp.Attr.checkId(Attr.java:3488)
at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3370)
at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1843)
at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
at com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:386)
at com.sun.tools.javac.comp.DeferredAttr$2.complete(DeferredAttr.java:279)
at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:245)
at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:232)
at com.sun.tools.javac.comp.Resolve$MethodResultInfo.check(Resolve.java:993)
at com.sun.tools.javac.comp.Resolve$4.checkArg(Resolve.java:826)
at com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.argumentsAcceptable(Resolve.java:731)
at com.sun.tools.javac.comp.Resolve$4.argumentsAcceptable(Resolve.java:835)
at com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:576)
at com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:1431)
at com.sun.tools.javac.comp.Resolve.findMethodInScope(Resolve.java:1618)
at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1689)
at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1662)
at com.sun.tools.javac.comp.Resolve$9.doLookup(Resolve.java:2415)
at com.sun.tools.javac.comp.Resolve$BasicLookupHelper.lookup(Resolve.java:3074)
at com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3325)
at com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2412)
at com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2406)
at com.sun.tools.javac.comp.Attr.selectSym(Attr.java:3395)
at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3281)
at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1843)
at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:656)
at com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1611)
at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1296)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:692)
at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1142)
at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1035)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4342)
at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4252)
at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4181)
at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4156)
at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1248)
at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:169)
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:785)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package it.giacomobergami.datatypelang.utils;
import java.util.function.Function;
/**
* Created by vasistas on 11/12/16.
*/
public interface ThrowableFunction<K,V,E extends Throwable> {
V apply(K k) throws E;
}
////
package it.giacomobergami.datatypelang.utils;
import java.util.function.Function;
public class OnExcpt<X,K> {
private final X elem;
public OnExcpt(X e) {
this.elem = e;
}
public <E extends Throwable> K as(ThrowableFunction<X,K,E> sup, Function<X,K> def) {
try {
return sup.apply(elem);
} catch (Throwable throwable) {
return def.apply(elem);
}
}
public static void main(String args[]) {
System.out.println(new OnExcpt<String,String>("ciao").as(s -> {
throw new RuntimeException();
}, x -> "cicco"));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Not known