-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JDK 14 + preview-features not working correctly #1167
Comments
58.65535 says to me that the class file was built with preview features enabled. If I understand the error message correctly, it is saying that when the class file is loaded by the JVM, that preview features are not enabled. That is, enable-preview was true for compile but not for execute. I think a workaround would be to set "--enable-preview" on the java that runs your eclipse (or maven as the case may be). Update: I was able to generate a similar error and resolve it for a maven build like this: https://github.com/groovy/groovy-eclipse/tree/master/extras/groovy-eclipse-compiler-tests/src/it/enable-preview/pom.xml I did not see an error during conversion. I will need more context to understand that. |
This may not mean much, but for reference this is the code that generates the "Expression$..." class (from public static Object evaluateExpression(Expression expr, CompilerConfiguration config) {
String className = "Expression$" + UUID.randomUUID().toString().replace('-', '$');
ClassNode node = new ClassNode(className, Opcodes.ACC_PUBLIC, OBJECT_TYPE);
ReturnStatement code = new ReturnStatement(expr);
addGeneratedMethod(node, "eval", Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, code);
CompilerConfiguration copyConf = new CompilerConfiguration(config);
CompilationUnit cu = new CompilationUnit(copyConf);
cu.addClassNode(node);
cu.compile(Phases.CLASS_GENERATION);
List<GroovyClass> classes = (List<GroovyClass>) cu.getClasses();
Class aClass = cu.getClassLoader().defineClass(className, classes.get(0).getBytes());
try {
return aClass.getMethod("eval").invoke(null);
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new GroovyBugError(e);
}
} Your groovy source ( |
This is the source of the classes @edu.umd.cs.findbugs.annotations.SuppressFBWarnings([
"MF_CLASS_MASKS_FIELD", "EI_EXPOSE_REP", "EI_EXPOSE_REP2", "HE_EQUALS_NO_HASHCODE",
"EQ_DOESNT_OVERRIDE_EQUALS", "ES_COMPARING_STRINGS_WITH_EQ", "HE_INHERITS_EQUALS_USE_HASHCODE",
"EC_UNRELATED_TYPES_USING_POINTER_EQUALITY", "EC_UNRELATED_TYPES_USING_POINTER_EQUALITY"
])
@JsonInclude(Include.NON_NULL)
@Sortable(includes = ["value", "currencyCode"])
@Canonical
@ToString(includes = ["currencyCode", "value"], ignoreNulls = true, includeNames = true, includePackage = false)
class PriceData extends Bean {
Boolean customPrice
Boolean fromPrice
Boolean maxWeightExceeded
@JsonInclude(Include.ALWAYS)
BigDecimal value
String currencyCode
PriceData() {
}
PriceData(Currency currency) {
this.currencyCode = currency?.getCurrencyCode()
}
PriceData(double value, Currency currency) {
this(BigDecimal.valueOf(value), currency)
}
PriceData(BigDecimal value, Currency currency) {
this(currency)
this.value = value
}
boolean isFromPrice() {
return fromPrice != null ? fromPrice : false
}
boolean isCustomPrice() {
return customPrice != null ? customPrice : false
}
void setCustomPrice(Boolean customPrice) {
this.customPrice = customPrice;
}
@JsonIgnore
Currency getCurrency() {
return currencyCode != null ? Currency.getInstance(currencyCode) : null
}
}
import org.apache.commons.lang3.builder.EqualsBuilder
import org.apache.commons.lang3.builder.HashCodeBuilder
import org.apache.commons.lang3.builder.ReflectionToStringBuilder
import org.apache.commons.lang3.builder.ToStringStyle
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings([ "MF_CLASS_MASKS_FIELD",
"EI_EXPOSE_REP", "EI_EXPOSE_REP2", "HE_EQUALS_NO_HASHCODE",
"EQ_DOESNT_OVERRIDE_EQUALS", "EQ_UNUSUAL" ])
@JsonInclude(value = Include.NON_NULL)
@JsonIgnoreProperties(["metaClass"])
abstract class Bean {
LocalDateTime createdAt
LocalDateTime modifiedAt
@Override
int hashCode() {
return HashCodeBuilder.reflectionHashCode(this, true)
}
@Override
boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj, true)
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.JSON_STYLE);
}
} |
And what does your |
import org.codehaus.groovy.ast.ClassNode
import groovy.transform.CompileStatic
withConfig(configuration) {
// inject compile static annotation into every class except for test classes
source(classValidator: { ClassNode cn -> !cn.name.endsWith("Spec") && !cn.name.endsWith("SpecIT") }) {
ast(CompileStatic)
// ast(TypeChecked)
}
//enable new groovy 3/java 11 syntax
// configuration.pluginFactory = ParserPluginFactory.antlr4(configuration)
} |
The latest snapshot builds should not run into this problem for expression evaluation. Any other class loading from your project may still have this issue. You'll have to let me know if you get any more of these with a different stack trace. If you add |
Seems to work fine again! Thanks for the quick fix. |
Hello,
our project uses maven with eclipse 4.16 and 4.17, latest greclipse release (also same on snapshot) java 14, groovy 3 and joint compilation, configured like this:
Today I updated the groovy plugin and all of a sudden the code in eclipse doesnot compile anymore.
This error is reported:
Groovy:General error during conversion: java.lang.UnsupportedClassVersionError: Preview features are not enabled for Expression$47d4a77a$cf5f$4775$8b57$07d99aa7e980 (class file version 58.65535). Try running with '--enable-preview' PriceData.groovy
Preview features are enabled on the Eclipse jvm compiler settings too. And it worked up till now!
Yesterday (or the day before) there was an update too and there it still worked.
The text was updated successfully, but these errors were encountered: