You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Freeman Yue Fang (Jira)" <ji...@apache.org> on 2021/09/10 17:42:00 UTC

[jira] [Assigned] (CAMEL-16943) MainPropertyPlaceholderWithEnvTest failed with JDK17

     [ https://issues.apache.org/jira/browse/CAMEL-16943?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Freeman Yue Fang reassigned CAMEL-16943:
----------------------------------------

    Assignee: Freeman Yue Fang

> MainPropertyPlaceholderWithEnvTest failed with JDK17
> ----------------------------------------------------
>
>                 Key: CAMEL-16943
>                 URL: https://issues.apache.org/jira/browse/CAMEL-16943
>             Project: Camel
>          Issue Type: Test
>          Components: camel-main
>            Reporter: Freeman Yue Fang
>            Assignee: Freeman Yue Fang
>            Priority: Major
>
> get exception like
> {code}
> Suppressed: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible: module java.base does not "opens java.util" to unnamed module @bf20622
> 		at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
> 		at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
> 		at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
> 		at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
> 		at org.apache.camel.main.MainPropertyPlaceholderWithEnvTest.getFieldValue(MainPropertyPlaceholderWithEnvTest.java:276)
> 		at org.apache.camel.main.MainPropertyPlaceholderWithEnvTest.getEditableMapOfVariables(MainPropertyPlaceholderWithEnvTest.java:226)
> 		at org.apache.camel.main.MainPropertyPlaceholderWithEnvTest.doEnvVariable(MainPropertyPlaceholderWithEnvTest.java:206)
> 		at org.apache.camel.main.MainPropertyPlaceholderWithEnvTest.tearDown(MainPropertyPlaceholderWithEnvTest.java:182)
> 		at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 		at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
> 		at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 		at java.base/java.lang.reflect.Method.invoke(Method.java:568)
> {code}
> This is because System.getEnv() returns a java.util.Collections$UnmodifiableMap which isn't supposed to be changed during runtime code. To workaround this, normally we need to use reflection way to make a private field in java.util.Collections$UnmodifiableMap accessible.
> But this is kind of against the encapsulation(Strongly Encapsulate JDK Internals ) rule of java Modules since JDK9. Before JDK17,  it is it  possible to access internal APIs via the --illegal-access command line option which is enabled by default. However, since JDK17 this --illegal-access is removed and we need to either explicitly use --add-opens modules to enable deep reflection for JDK internal code, or we need to get rid of the way to use JDK Internals



--
This message was sent by Atlassian Jira
(v8.3.4#803005)