-
-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[type hierarchy] Method references of public classes refer to non-visible methods of sub-classes #1326
Comments
First of all we can move all tests to another package |
Mmhh, interesting idea. We could do that! |
Came here from Twitter, sorry for barging in. Are you sure this is the correct analysis? It sounds very "un-Java" and I can not reproduce it in a simple setup (Gist pending). |
Here's the Gist. I can't see anything unusual. |
Gonna keep spamming... :) This looks like the same case: IllegalAccessError when using a public method reference of a package-private class through a public subclass from another package |
Hi Nicolai, I like that kind of spam! More of that :) Btw: I'm a big fan of your blog, great stuff! |
@ruslansennov hold your horses (moving the tests). In the case of a jdk bug we should wait for a fix. |
As a side node: doesn't work on 25.66-b00-graal-vm-0.10 either (same for some old 1.9.0-ea-b90 I still had lying around). |
The tests in Nicolai's gist show that
|
Just pitching in some (maybe not useful) theory here: Is AbstractMap a key piece in Map's type hierarchy? If not, maybe this is one of those cases where we try to apply inheritance wrongly while pursuing code reuse. Code in AbstractMap can be reused without inheritance. Package local static methods will work and what has to be weighed here is the trade off of having some calls duplicated in classes that should use AbstractMap's methods. |
@ggalmazor yes, that's what I also thinking about - pulling the AbstractXxx classes out of the Even if it is a JDK bug and it will be (or already is?) fixed in a future JDK version, it would be more robust to make it work independent of a specific JDK version. |
Glad to hear that from you. I deal with this kind of problems in my daily work a lot and sometimes it's hard to explain this to people. 👍 |
Even if we rename the test packages we can't ensure that we make exhaustive tests by checking if all methods have sufficient visibility in sub-classes when used in conjunction with method references. Another approach to test it would be to create a test class
We do not need to do this for release 2.1.0 because it is a nice to have test but it would help to make Javaslang more robust regarding further development. Towards release 2.1.0 we will look with a sharp eye if there are potential spots that may make problems. Candidates are our (new) abstract collection classes that are package private:
But these types should not introduce new API, I think there are public interfaces that already define the methods, so there should no |
Related to JDK Bug 8141122 |
(Found a JDK type inference bug on the way fixing the JDK bug of this issue. Details here: https://gist.github.com/danieldietrich/18902076d53ef09b5c90472b613be85b) |
Replaces AbstractMap with Maps. Towards #1326
Added BitSet method reference test. Towards #1326
Not sure if this changes anything, byt judging from https://www.youtube.com/watch?v=QnMDsI2GbOc this may be a non-issue in |
For now we stay backward-compatible to Java 8. Even Javaslang 3.0.0 will not be lifted to Java 9 as minimum version because there are no specific features we could use to make life easier for our users. Java 10 will be different :) |
I agree, it's just a FYI :) |
Yes, more fine-grained visibility features are very nice. What I still miss are |
Needs to be re-evaluated, if it is still a problem with Java 11. |
In Vavr 1.0 we will not have non-visible abstract classes. Our inline code generator will inject shared code. |
@tcn reported the following:
HashMap
has no declared methodmerge
. It inheritsmerge
fromAbstractMap
. The method referenceHashMap::merge
internally points toAbstractMap::merge
. Because our classAbstractMap
is package private, we get ajava.lang.IllegalAccessError
.We need to check sub-classes of all package private classes!
The solution which solves this bug should not make internal classes like
AbstractMap
visible. It is not intended to be public API, we added it to reduce code duplication. We could override the methods in the sub-classes and delegate to the methods of the package-private super-class. Maybe it is also an option not to inherit from package-private classes, so we are forced to delegate (to static methods).The text was updated successfully, but these errors were encountered: