a change in javac behavior
Alan Snyder
javalists at cbfiddle.com
Sun Dec 17 16:48:15 UTC 2023
I’m experiencing a change in behavior compiling a particular file.
The compiler is trying to match an invocation to one of two constructors for a static class defined in the same file.
The second constructor has a parameter of type Builder. In the past, this was interpreted as my Builder class, which is imported into this file.
That matches the invocation.
Now, however, the constructor parameter type is interpreted as java.lang.Thread.Builder, presumably because the static class extends Thread.
That causes a mismatch to be reported.
This interpretation appears to be limited to the resolution of the constructor invocation. Within the constructor, I do not get an error when the parameter
is used as an instance of my Builder class.
This happens in JDK 20, JDK 21, and the latest build of JDK 22.
It does not happen in JDK 17.
The error message:
[javac] constructor Worker.Worker(@org.jetbrains.annotations.NotNull String, at org.jetbrains.annotations.NotNull SeverityLevel, at org.jetbrains.annotations.NotNull java.lang.Thread.Builder, at org.jetbrains.annotations.Nullable TaskStatusListener, at org.jetbrains.annotations.NotNull SimpleTaskReceiver<BuildResult>) is not applicable
[javac] (argument mismatch; @org.jetbrains.annotations.NotNull com.cbfiddle.releases.Builder cannot be converted to @org.jetbrains.annotations.NotNull java.lang.Thread.Builder)
The constructor:
public Worker(@NotNull String taskName,
@NotNull SeverityLevel level,
@NotNull Builder builder,
@Nullable TaskStatusListener tsl,
@NotNull SimpleTaskReceiver<BuildResult> r)
{
this.taskName = taskName;
this.level = level;
this.r = r;
this.bl = createBuildListener(tsl);
this.op = () -> builder.perform(bl);
setPriority(Thread.MIN_PRIORITY);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20231217/00e179b0/attachment-0001.htm>
More information about the compiler-dev
mailing list