RFR: 8343286: Missing unchecked cast warning in polymorphic method call [v4]
Vicente Romero
vromero at openjdk.org
Tue Nov 12 15:13:41 UTC 2024
> Javac is not issuing a mandated unchecked cast warning for code like:
>
>
> import java.lang.invoke.VarHandle;
>
> class VarHandleCast<V> {
> VarHandle vh;
> V method(Object obj) {
> return (V)vh.getAndSet(this, obj);
> }
> }
>
>
> according to the spec the return type inferred for this method polymorphic method should be Object see:
>
> - If the compile-time declaration for the method invocation is a signature polymorphic method, then:
> ...
> – The compile-time result is determined as follows:
> Otherwise, if the method invocation expression is the operand of a cast
> expression (§15.16), the compile-time result is the erasure of the type of the
> cast expression (§4.6).
>
> javac is not doing the type erasure mandated by the spec which is what this PR is fixing
>
> TIA
>
> Note: I had to add some annotations to suppress warnings in java.base that were not being issued before due to the javac bug
Vicente Romero has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains six additional commits since the last revision:
- Merge branch 'master' into JDK-8343286
- Merge branch 'master' into JDK-8343286
- fixing build error
- Merge branch 'master' into JDK-8343286
- fixing build error
- 8343286: Redundant cast in polymorphic method call
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/21914/files
- new: https://git.openjdk.org/jdk/pull/21914/files/5bfcf8ef..f66ee79d
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=21914&range=03
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=21914&range=02-03
Stats: 15056 lines in 470 files changed: 11106 ins; 2074 del; 1876 mod
Patch: https://git.openjdk.org/jdk/pull/21914.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/21914/head:pull/21914
PR: https://git.openjdk.org/jdk/pull/21914
More information about the compiler-dev
mailing list