Luk*_*der 7 java compilation jooq java-8
向jOOQ用户组报告了以下错误.它似乎是javac编译器中的一个错误,它与编译器在使用内部DSL(如jOOQ)的上下文中完成的"复杂"类型推理工作有关.
鉴于bug的一般性质,我在Stack Overflow上记录它,以便其他人帮助应用变通方法.在高层次上,由于JEP 101:广义目标类型推断,它似乎是编译器性能回归,它是在Java 8中引入的,并且在过去已经引起了1-2个问题.
使用Maven和jOOQ 3.7在Windows上使用jdk 1.8.0_60或1.8.0_66编译以下相对无害的类大约需要20秒:
import static org.jooq.impl.DSL.field;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
public class Test {
public void method() {
DSL.using(SQLDialect.MYSQL)
.select()
.where(DSL.trueCondition())
.and(field("client.id").eq(field("client_id")))
.and(field("client.id").eq(field("client_id")))
.and(field("client.id").eq(field("client_id")))
.and(field("client.id").eq(field("client_id")))
.and(field("client.id").eq(field("client_id")))
.and(field("client.id").eq(field("client_id")))
.and(field("client.id").eq(field("client_id")))
.and(field("client.id").eq(field("client_id")))
.and(field("client.id").eq(field("client_id")))
.and(field("client.id").eq(field("client_id")))
;
}
}
Run Code Online (Sandbox Code Playgroud)
pom.xml中:
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>compilation-issues</groupId>
<artifactId>compilation-issues</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.7.1</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
在jOOQ 3.6中(首次出现此问题时),DSL.field()API看到22个新的重载,它们使用不同Row类型作为参数:
看来,通过上面这个特定的API用法,当javac编译器试图在所有可能的重载中找到最具体的重载时,新的重载会导致很多麻烦.以下解决方法立即编译:
一个修复程序下发行方式3.9.0,3.8.1,3.7.4,3.6.5,从公共API再次删除这些方法,并提供改名替代品不会造成任何超载的问题.
DSL.field()重载import static org.jooq.impl.DSL.field;
import org.jooq.Field;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
public class Test {
public void method() {
Field<Object> f1 = field("client.id");
Field<Object> f2 = field("client_id");
DSL.using(SQLDialect.MYSQL)
.select()
.where(DSL.trueCondition())
.and(f1.eq(f2))
.and(f1.eq(f2))
.and(f1.eq(f2))
.and(f1.eq(f2))
.and(f1.eq(f2))
.and(f1.eq(f2))
.and(f1.eq(f2))
.and(f1.eq(f2))
.and(f1.eq(f2))
.and(f1.eq(f2))
;
}
}
Run Code Online (Sandbox Code Playgroud)
and()方法上下文中的目标类型推断import static org.jooq.impl.DSL.field;
import org.jooq.Condition;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
public class Test {
public void method() {
Condition condition = field("client.id").eq(field("client_id"));
DSL.using(SQLDialect.MYSQL)
.select()
.where(DSL.trueCondition())
.and(condition)
.and(condition)
.and(condition)
.and(condition)
.and(condition)
.and(condition)
.and(condition)
.and(condition)
.and(condition)
.and(condition)
;
}
}
Run Code Online (Sandbox Code Playgroud)
这实际上已在Stack Overflow上报告过:
在jOOQ用户组中也讨论过它:
| 归档时间: |
|
| 查看次数: |
1626 次 |
| 最近记录: |