All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.samples.java.ex.RFI_Sample Maven / Gradle / Ivy

Go to download

An auxiliary findbugs.sourceforge.net plugin for java bug detectors that fall outside the narrow scope of detectors to be packaged with the product itself.

There is a newer version: 7.6.8
Show newest version
package ex;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;

public class RFI_Sample {

    public void accessSingleField() throws Exception {

        String s = "Hello";

        Field f = String.class.getDeclaredField("value");
        f.setAccessible(true);

        byte[] data = (byte[]) f.get(s);
        data[1] = 'a';

        System.out.println(s);
    }

    public void accessMultipleFields() throws Exception {
        String s = "Hello";

        Field f = String.class.getDeclaredField("value");
        Field g = String.class.getDeclaredField("hash");
        AccessibleObject.setAccessible(new Field[] { f, g }, true);

        byte[] data = (byte[]) f.get(s);
        data[1] = 'a';

        g.set(s, 0);

        System.out.println(s);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy