public void toXMLUTF8(Object obj, OutputStream out) throws IOException {
        Writer w = new OutputStreamWriter(out, StandardCharsets.UTF_8);
        w.write("<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n");
        toXML(obj, w);
    }
@Issue("JENKINS-71139")
    @Test
    public void nullsWithEncodingDeclaration() throws Exception {
        Bar b = new Bar();
        b.s = "x\u0000y";
        try {
            new XStream2().toXMLUTF8(b, new ByteArrayOutputStream());
            fail("expected to fail fast; not supported to read either");
        } catch (RuntimeException x) {
            assertThat("cause is com.thoughtworks.xstream.io.StreamException: Invalid character 0x0 in XML stream", Functions.printThrowable(x), containsString("0x0"));
        }
    }