Regression: accessing a private method through a type variable
forax at univ-mlv.fr
forax at univ-mlv.fr
Tue Oct 24 20:20:42 UTC 2023
> From: "Vicente Romero" <vicente.romero at oracle.com>
> To: "Maurizio Cimadamore" <maurizio.cimadamore at oracle.com>,
> "SUNDARARAJAN.ATHIJEGANNATHAN" <sundararajan.athijegannathan at oracle.com>, "Remi
> Forax" <forax at univ-mlv.fr>, "compiler-dev" <compiler-dev at openjdk.org>
> Sent: Tuesday, October 24, 2023 7:24:35 PM
> Subject: Re: Regression: accessing a private method through a type variable
> Hi Remi,
> Thanks again for the report, we have already fixed it, see [1] for more details,
> Vicente
Hello Vincente,
thanks for fixing that issue, for the anecdote, this issue was found doing mob programming [1] with my students.
I think next week, we will study how the regression was introduced and and how you and Maurizio fix it :)
Rémi
[1] https://en.wikipedia.org/wiki/Team_programming#Mob_programming
> On 10/16/23 11:46, Vicente Romero wrote:
>> Thanks for the report, we have created [1]. I'm taking a look at it,
>> Vicente
>> [1] [ https://bugs.openjdk.org/browse/JDK-8318160 |
>> https://bugs.openjdk.org/browse/JDK-8318160 ]
>> On 10/16/23 07:15, Maurizio Cimadamore wrote:
>>> I recall fixing this a long time ago:
>>> [ https://bugs.openjdk.org/browse/JDK-6711619 |
>>> https://bugs.openjdk.org/browse/JDK-6711619 ]
>>> Now, the test case mentioned in that bug is still correctly rejected by javac.
>>> Furhermore, a similar test:
>>> ```
>>> class X<E extends X<E>> {
>>> private static int m() { return 1; }
>>> int f() {
>>> return E.m();
>>> }
>>> }
>>> ```
>>> Also fails to compile with 21/22.
>>> ```
>>> Test.java:5: error: m() has private access in X
>>> return E.m();
>>> ^
>>> 1 error
>>> ```
>>> Trying to manipulate Remi's example, it seems the regression only has to do with
>>> method refreences whose receiver is a type variable.
>>> Here's a minimal reproducer:
>>> ```
>>> import java.util.function.*;
>>> class Test {
>>> private String asString() {
>>> return "bar";
>>> }
>>> static <T extends Test> Function<T, String> foo() {
>>> return T::asString;
>>> }
>>> }
>>> ```
>>> I filed a bug:
>>> [ https://bugs.openjdk.org/browse/JDK-6711619 |
>>> https://bugs.openjdk.org/browse/JDK-6711619 ]
>>> Thanks
>>> Maurizio
>>> On 16/10/2023 10:40, Sundararajan Athijegannathan wrote:
>>>> fwiw, this compile from at least JDK 11 onwards:
>>>> import java.util.*;
>>>> import java.util.stream.*;
>>>> public class TDotToString {
>>>> class Bar {
>>>> private String asString() {
>>>> return "bar";
>>>> }
>>>> }
>>>> static <T extends Bar> String foo(List<T> list) {
>>>> return list.stream().map(T::asString).collect(Collectors.joining());
>>>> }
>>>> }
>>>> javac from 1.8.0 does issue error as mentioned by Remi.
>>>> -Sundar
>>>> From: compiler-dev [ mailto:compiler-dev-retn at openjdk.org |
>>>> <compiler-dev-retn at openjdk.org> ] on behalf of Remi Forax [
>>>> mailto:forax at univ-mlv.fr | <forax at univ-mlv.fr> ]
>>>> Sent: 16 October 2023 13:57
>>>> To: compiler-dev [ mailto:compiler-dev at openjdk.org | <compiler-dev at openjdk.org>
>>>> ]
>>>> Subject: Regression: accessing a private method through a type variable
>>>> Hello,
>>>> There is a regression in recent versions of javac.
>>>> javac 21 allows to access a private method through a type variable, here
>>>> T::asString.
>>>> public class TDotToString {
>>>> class Bar() {
>>>> private String asString() {
>>>> return "bar";
>>>> }
>>>> }
>>>> static <T extends Bar> String foo(List<T> list) {
>>>> return list.stream().map(T::asString).collect(Collectors.joining());
>>>> }
>>>> }
>>>> Both IntelliJ and Eclipse emit an error in this case.
>>>> And javac 8 emits
>>>> TDotToString.java:12: error: invalid method reference
>>>> return list.stream().map(T::asString).collect(Collectors.joining());
>>>> ^
>>>> cannot find symbol
>>>> symbol: method asString()
>>>> location: bound of type variable T
>>>> where T is a type-variable:
>>>> T extends TDotToString.Bar declared in method <T>foo(List<T>)
>>>> 1 error
>>>> regards,
>>>> Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20231024/6cd94e0d/attachment-0001.htm>
More information about the compiler-dev
mailing list