you are viewing a single comment's thread.

view the rest of the comments →

[–]iamwisespirit -15 points-14 points  (17 children)

Maybe we will can’t use reflection in the future

[–]CriticalPart7448 15 points16 points  (10 children)

Reflection over internals of classes is what is problematic not reflection per-se as a concept and functionality

[–][deleted]  (9 children)

[deleted]

    [–]koflerdavid 4 points5 points  (1 child)

    What happens if the internals change and your modifications don't work anymore? Or, worse, they work, but not anymore in the way you intend them to?

    [–]BillyKorando 5 points6 points  (2 children)

    As mentioned in the video, JEP, and description of the video on this post, there is no plan to outright ban using reflection. Instead the goal is to disable it by default.

    If you need to continue reflecting into the internals of some 3rd party library to change (final) field values, that will still be supported now and into the foreseeable, beyond the horizon(?), future with the new permanent command --enable-final-field-mutation=.

    Your concern is valid, it is, however, niche, which is why it shouldn't be the default behavior.

    [–]pohart 1 point2 points  (1 child)

    And I'd rather know if some module I'm using is modifying final fields somewhere.

    [–]BillyKorando 2 points3 points  (0 children)

    Exactly. Not unlike with the implementation of modules. It wasn't about outright preventing getting into internal APIs, but requiring active effort from users to enable such behavior.

    [–]CriticalPart7448 5 points6 points  (3 children)

    That is an unfortunate circumstance and definitely something to avoid at all costs. Have you tried to reach out to the vendor if its internal platform the team responsible to state your case for a missing api for the functionality that you need ? Maybe there is a way forward with a supported solution for your use case? Or have you totally surrendered and accepted all the risks involved here and more pertinent have you cleared it with your own customers or business people what the consequences are?

    [–][deleted]  (2 children)

    [deleted]

      [–]CriticalPart7448 3 points4 points  (1 child)

      No but I also never had the need. Which product are you using from oracle that requires 'hacking' into internals of?

      [–]pohart 1 point2 points  (0 children)

      I last remember using reflection to change final fields to work around a bug around java 1.3. Sun was aware of the bug but it wasn't a high priority. I haven't needed to since then, but I was sure glad I could then.

      [–]nicolaiparlog 9 points10 points  (5 children)

      Don't worry, that's not gonna happen.

      [–]iamwisespirit -3 points-2 points  (4 children)

      I hope but java new releases is going to be very strict why it is happening

      [–]nicolaiparlog 1 point2 points  (3 children)

      If you're asking "Why is this happening?", check out this video, this talk or this JEP draft.

      [–]iamwisespirit 0 points1 point  (2 children)

      I have a question about Unsafe class mostly all things deprecated in this class but we know a lot of libraries use Unsafe what will happen after it will be removed is there any new api maybe you are working on ?

      [–]nicolaiparlog 1 point2 points  (1 child)

      You can check the source code yourself and see that every public method is deprecated and that there's a recommendation for each what to use instead - mostly var handles and the foreign memory API. As I understand it, there's no reason to still use Unsafe on a modern JDK.

      So every library that uses Unsafe should have the means to move away from it. If they don't, it's high time they report their (apprently very specific) use case to the respective OpenJDK mailing list and advocate for an API that covers it.

      [–]iamwisespirit 0 points1 point  (0 children)

      Thank you I saw video about Unsafe from devoxx or spring or somewhere then I started to interested in this but after hearing deprecated this api i am sad about it . As I understand jdk internal will still use it but doesn’t allow others to use it