#vulnerable code 
                                public static String stringValue(Instance obj) {
        if (obj == null) {
            return null;
        }
        if (!"java.lang.String".equals(obj.getJavaClass().getName())) {
            throw new IllegalArgumentException("Is not a string: " + obj.getInstanceId() + " (" + obj.getJavaClass().getName() + ")");
        }
        char[] text = null;
        int offset = 0;
        int len = -1;
        for(FieldValue f: obj.getFieldValues()) {
            Field ff = f.getField();
            if ("value".equals(ff.getName())) {
                PrimitiveArrayInstance chars = (PrimitiveArrayInstance) ((ObjectFieldValue)f).getInstance();
                text = new char[chars.getLength()];
                for(int i = 0; i != text.length; ++i) {
                    text[i] = ((String)chars.getValues().get(i)).charAt(0);
                }
            }
            // fields below were removed in Java 7
            else if ("offset".equals(ff.getName())) {
                offset = Integer.valueOf(f.getValue());
            }
            else if ("count".equals(ff.getName())) {
                len = Integer.valueOf(f.getValue());
            }
        }

        if (len < 0) {
            len = text.length;
        }

        return new String(text, offset, len);
    } 
                            #location 30 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                                public static String stringValue(Instance obj) {
		if (obj == null) return null;

		if (!"java.lang.String".equals(obj.getJavaClass().getName()))
			throw new IllegalArgumentException("Is not a string: " + obj.getInstanceId() + " (" + obj.getJavaClass().getName() + ")");

		Boolean COMPACT_STRINGS = (Boolean) obj.getJavaClass().getValueOfStaticField("COMPACT_STRINGS");
		if (COMPACT_STRINGS == null)
			return stringValue_java8(obj); // We're pre Java 9

		Object valueInstance = obj.getValueOfField("value");
		PrimitiveArrayInstance chars = (PrimitiveArrayInstance) valueInstance;

		byte UTF16 = 1;
		byte coder = COMPACT_STRINGS ? (Byte) obj.getValueOfField("coder") : UTF16;
		int len = chars.getLength() >> coder;
		char[] text = new char[len];

		List<String> values = (List) chars.getValues();
		if (coder == UTF16)
			for (int i = 0; i < text.length; i++) {
				text[i] = (char)
				    ((Integer.parseInt(values.get(i*2+1)) << 8)
				   | (Integer.parseInt(values.get(i*2)) & 0xFF));
			}
		else
			for (int i = 0; i < text.length; i++)
				text[i] = (char) Integer.parseInt(values.get(i));

		return new String(text);
	}