I have an OSGi bundle b1 exporting a class with
public static final String MYVAL = "a"; //version 1
and a second bundle b2 is compiled and deployed using version 1 of b1.
Later on I change the value in b1 to
public static final String MYVAL = "b"; //version 2
but I only recompile and deploy b1, b2 is unchanged and not recompiled.
Is it possible that the b2 still sees value a at runtime?
The value of a referenced static final primitive or string is directly inlined into the using class. So unrelated to OSGI and any visibility rules,
b2will still contain an embeddedMYVALvalue of “a”.I think this is documented in the Java Language Specification, Section 13.4:
This answer to a similar question shows a workaround. Changing the declaration so it is no longer a constant expression disables this inlining behaviour.