回复:VM crashed at StringTable expansion

Florian Weimer fweimer at redhat.com
Wed Feb 26 12:08:01 UTC 2020


* 向伟(识月):

> Hi Florian,
>
> This isn't a common usage.
> For the below code:
>
> String s1 = "s1".intern();
> f.set("s1".intern(), f.get("s2"));
>
> After calling reflection, the value of s1 is changed to "s2".
> In some special scenarios, the original jar file can't be modified. But the user 
> expects to change the value of some string, and uses the above code to
> implement it.
>
> Although this usage isn't recommended, it isn't forbidden. We don't expect
> the crash because of the usage.

That's not what I see.  A modified reproducer:

import java.lang.reflect.Field;
public class StringTableTest {
    public static void main(String[] args) throws Exception {
        Field f = String.class.getDeclaredField("value");
        f.setAccessible(true);
        f.set("s1".intern(), f.get("s2"));
        System.out.println("s1");
        System.out.println("s2");
    }
}

Prints this:

s2
s2

It also has a clear warning:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by StringTableTest (file:/tmp/) to field java.lang.String.value
WARNING: Please consider reporting this to the maintainers of StringTableTest
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

I'm not sure what else we can do.

Thanks,
Florian



More information about the hotspot-runtime-dev mailing list