Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] java.lang.reflect.InaccessibleObjectException error in webapp

On 8/22/2024 2:23 AM, Simone Bordet wrote:

You should bring this issue to the Spring Project.

Errors of this kind may stem from the wrong usage of reflection, for example:

Thanks for the explanation; this is a bit deeper in java theory than I usually operate at :). I'm confused though, as most of the discussion around this issue involves code that is just broken until fixed, and the general suggestion is to fix your code. However, it appears in this case that sometimes the code works, and sometimes it doesn't?

I see Scott replied and thinks it's a race condition; based on his hypothesis that it is more likely to occur under load, something gets accessed before fully initialized? Or a call to something sooner than something else makes a class get loaded from one jar rather than another? Definitely out of my depth on this.

A suggested workaround is to add "--add-opens java.base/java.util=ALL-UNNAMED" to the jvm startup arguments. Would that prevent the problem when the race condition is lost for this issue? If so, would it have any undesirable security aspects that make it a bad idea?

Thanks much…

Object iter = new LinkedHashMap().iterator();
iter.getClass().getMethod("hasNext").invoke(iter); // throws
Iterator.class.getMethod("hasNext").invoke(iter); // ok

The problem is iter.getClass() that returns the private JDK class,
while Iterator.class is the public JDK class that should be used.

In this specific case, there could be more, but it's a Spring issue,
not Jetty's.



Back to the top