Skip to content
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

Add support for Java 16 records #829

Open
htsaustin opened this issue Mar 17, 2021 · 2 comments · May be fixed by #840
Open

Add support for Java 16 records #829

htsaustin opened this issue Mar 17, 2021 · 2 comments · May be fixed by #840

Comments

@htsaustin
Copy link

Java 16 has added support for records under JEP 395, of the form.

public record Point(int x, int y) {
}

It would be great to support these in JavaPoet, as among other things, they significantly reduce boilerplate.

liach added a commit to liachmodded/javapoet that referenced this issue May 13, 2021
Fixes square#829

Signed-off-by: liach <liach@users.noreply.github.com>
liach added a commit to liachmodded/javapoet that referenced this issue May 13, 2021
Fixes square#829

Signed-off-by: liach <liach@users.noreply.github.com>
@liach liach linked a pull request May 13, 2021 that will close this issue
@rbair23
Copy link

rbair23 commented Jul 8, 2022

I am taking a crack at a PR that would add record support. However, after forking and doing a fresh build/test, I'm seeing two tests fail in IntelliJ (when running through the IDE, not in Maven).

ClassNameTest::classNameFromTypeElementDoesntUseGetKind fails:

java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol$Completer.complete(com.sun.tools.javac.code.Symbol)" because "c" is null

	at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:682)
	at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1410)
	at jdk.compiler/com.sun.tools.javac.code.Symbol.apiComplete(Symbol.java:688)
	at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.getKind(Symbol.java:1476)
	at com.squareup.javapoet.ClassNameTest.preventGetKind(ClassNameTest.java:135)
	at com.squareup.javapoet.ClassNameTest.classNameFromTypeElementDoesntUseGetKind(ClassNameTest.java:122)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

and ParameterSpecTest::parameterVariableElement fails:

expected: java.lang.String arg0
but was : java.lang.String bar
Expected :java.lang.String arg0
Actual   :java.lang.String bar
<Click to see difference>


	at com.squareup.javapoet.ParameterSpecTest.parameterVariableElement(ParameterSpecTest.java:121)

Is this expected?

@vkhodygo
Copy link

vkhodygo commented Sep 3, 2022

@rbair23 It looks like the latter can be fixed by replacing

.isEqualTo("java.lang.String arg0");

with

.isEqualTo("java.lang.String bar");

It's not clear to me yet what causes the other one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants