OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.15k stars 590 forks source link

Make osgi.Webcontainer's loadedContainerSpeclevel variable final #20096

Open volosied opened 2 years ago

volosied commented 2 years ago

Unit tests failed (when I tried to set the final variable via reflection)

I don't think I can set this to final without the unit tests failing. I kept getting: java.lang.IllegalAccessException: Can not set static final int field com.ibm.ws.webcontainer.osgi.WebContainer.loadedContainerSpecLevel to (int)30

I even tried using Field.setInt instead.

_Originally posted by @volosied in https://github.com/OpenLiberty/open-liberty/pull/20004#discussion_r803093599_

volosied commented 1 year ago

Code: https://github.com/OpenLiberty/open-liberty/blob/bf3c1822018bbf63d80f0517d009dc63b8fc25bc/dev/com.ibm.ws.webcontainer/src/com/ibm/ws/webcontainer/osgi/WebContainer.java#L247

The following post says:

If the underlying field is final, a Field object has write access if and only if

    -  setAccessible(true) has succeeded for this Field object;
    -  the field is non-static; and
    -  the field's declaring class is not a hidden class; and
    -  the field's declaring class is not a record class.

The second point looks to be the issue since our field is static.

@pnicolucci I'd like to close this issue unless you think we should change the unit test code?

pnicolucci commented 1 year ago

@volosied if we can make minor updates to the unit tests it would make sense to do so so we can mark this final in the runtime.