Skip to content

Fix compile errors for records with custom constructors, update JDT#10358

Open
zbynek wants to merge 3 commits into
gwtproject:mainfrom
zbynek:jdt
Open

Fix compile errors for records with custom constructors, update JDT#10358
zbynek wants to merge 3 commits into
gwtproject:mainfrom
zbynek:jdt

Conversation

@zbynek

@zbynek zbynek commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Updating JDT by itself is enough to fix the issue described in #10045 .

There is also a similar issue with

record RecordWithDefaultConstructor(String foo) {
  public RecordWithDefaultConstructor {
    Objects.requireNonNull(foo);
  }
}

where JDT provides two canonical constructors:

// this one has no binding
RecordWithDefaultConstructor(String foo) {
  super();
  .foo = foo;
}

// this one has a binding
public RecordWithDefaultConstructor(String foo) {
  super();
  Objects.requireNonNull(foo);
  this.foo = foo;
}

Skipping the one without a binding prevents a NPE.

Unit tests added for both, minor tweaks needed to make tests pass with new JDT.

Fixes #10045

Relies on gwtproject/tools#41

@zbynek zbynek changed the title Jdt Fix compile errors for records with custom constructors, update JDT Jul 3, 2026
@zbynek zbynek added the ready This PR has been reviewed by a maintainer and is ready for a CI run. label Jul 3, 2026
@zbynek zbynek force-pushed the jdt branch 6 times, most recently from 20b2d41 to 1f69840 Compare July 4, 2026 09:06
@zbynek zbynek marked this pull request as ready for review July 4, 2026 09:16
@zbynek zbynek requested a review from niloc132 July 4, 2026 17:44
Comment thread dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
@zbynek

zbynek commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@niloc132 the JSP test fails with

Compiling for Java version '1.7' is no longer supported. Minimal supported version is '1.8'

Stacktrace:
	at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
	at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:214)
	at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:611)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:381)

Given JettyLauncher's deprecated status, is this something worth spending time on, or can we just remove the test?

EDIT: I think I found a solution, but I'm not sure if it's too hacky.

Comment on lines +96 to +103
<param-value>%s</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>%s</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>""", jspLevel, jspLevel));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can avoid the repetition here

Suggested change
<param-value>%s</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>%s</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>""", jspLevel, jspLevel));
<param-value>%1$s</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>%1$s</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>""", jspLevel));

That said, it would be nice to explicitly escape this string just in case it is truly an arbitrary string

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple validation added instead of escaping.

Comment thread dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java Outdated
Comment thread dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java Outdated
}

protected String getJspLevel() {
return null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that JSPs don't work any more in dev mode? Did they before this patch?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did they before this patch?

Yes, if you either stick with Java 1.7 syntax or provide your own web.xml.

JSPs don't work any more in dev mode

If you provide your own web.xml (setting Java level to 1.8 or higher), they should still work. Without it, they will fail.

I wasn't sure what we want (could we break something by creating web.xml for projects that don't need it?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so need a release note entry on this, that 1.7 won't work any more, and newer formats require an explicit web.xml entry.

Co-authored-by: Colin Alworth <colin@vertispan.com>
@niloc132 niloc132 added this to the 2.14 milestone Jul 6, 2026
"package java.util;",
"public interface Map<K,V> { }");

public static final MockJavaResource METHOD_HANDLE =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going over the rest of GWT, I don't see actual emulation for these provided, so how does a normal compile have these (or not need them) while a test must get them from here?

I do see com.google.gwt.dev.javac.JdtCompiler.INameEnvironmentImpl#getLambdaMetafactoryBytes and friends, but nothing that provides MethodHandle or MethodHandles itself, nor StringConcatFactory. Does the newer JDT require these so we'll want general emulation for these, or maybe these were needed for an earlier iteration but no longer (e.g. to try to deal with emulating Record method before Objects was added)?

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

Labels

ready This PR has been reviewed by a maintainer and is ready for a CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding a custom record constructor prevents successful compilation

2 participants