[External] : Re: Regression: accessing a private method through a type variable

Vicente Romero vicente.romero at oracle.com
Thu Oct 26 04:57:51 UTC 2023


Hi Remi,

> Hello Vincente,
> thanks for fixing that issue, for the anecdote, this issue was found 
> doing mob programming [1] with my students.

interesting :)

> I think next week, we will study how the regression was introduced and 
> and how you and Maurizio fix it :)

:) this could be considered as software archeology

>
> Rémi
> [1] https://en.wikipedia.org/wiki/Team_programming#Mob_programming 
> <https://urldefense.com/v3/__https://en.wikipedia.org/wiki/Team_programming*Mob_programming__;Iw!!ACWV5N9M2RV99hQ!IqPY8L_FXrpGemBiKCbKjreCUO-icqhonFtyho2_ZUbn2rwFvsK3tI_OePWXLwuRJkV5mOxpJJsji1wXT0y1Ww$>

Say hello to your students :),
Vicente

>
>
>
>     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
>
>         On 10/16/23 07:15, Maurizio Cimadamore wrote:
>
>             I recall fixing this a long time ago:
>
>
>             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
>
>
>             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 <compiler-dev-retn at openjdk.org>
>                 on behalf of Remi Forax <forax at univ-mlv.fr>
>                 *Sent:* 16 October 2023 13:57
>                 *To:* compiler-dev <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/20231025/4275d5a2/attachment-0001.htm>


More information about the compiler-dev mailing list