javawriterstringwriter

Conflict Between StaticWriter and Writer Classes


As of our recent move from WSED 5.2 to RAD 7.5, an application-wrecking bug has appeared in our code.

RAD 7.5 marks it thusly, all at the declaration of the class header (public class FoStringWriter extends StringWriter implements FoWriter {)

- Exception IOException in throws clause of Writer.append(CharSequence, int, int) is not compatable with StringWriter.append(CharSequence, int, int)
- Exception IOException in throws clause of Writer.append(char) is not compatable with StringWriter.append(char)
- Exception IOException in throws clause of Writer.append(CharSequence) is not compatable with StringWriter.append(CharSequence)

Every piece of literature I have been able to find on the web points to this being a 'bug' in Eclipse, yet my developer should already have the most recent version of Eclipse software on it. So I am left not knowing what to make of this error. Is there a fix from IBM that I simply haven't yet updated to? Or is there a code-fix that could rectify this error?

public class FoStringWriter extends StringWriter implements FoWriter {

public void filteredWrite(String str) throws IOException {
FoStringWriter.filteredWrite(str,this);
}

public static void filteredWrite(String str, StringWriter writer) throws IOException {
    if (str == null) str = "";
    TagUtils tagUtils = TagUtils.getInstance();
    str = tagUtils.filter(str);
    HashMap dictionary = new HashMap();
    dictionary.put("&#","&#");
    str = GeneralUtils.translate(str,dictionary);
    writer.write(str);      
}

}

Editory Note:

The process that this runs creates PDF documents for our app. In WSED 5.5, it worked, had a few errors but nothing that stopped the PDF from being written.


Solution

  • Slap me in the forehead, because this is another "Error" solved by a seemingly completely obvious answer.

    Just by adding the listed methods that throw "errors", I can eliminate the error throwing when calling this class.

    Copying them straight from StringWriter actually worked, without editing them in any way.

    public StringWriter append(char c) {
        write(c);
        return this;
    }
    
    public StringWriter append(CharSequence csq) {
        if (csq == null)
            write("null");
        else
            write(csq.toString());
            return this;
    }
    
    public StringWriter append(CharSequence csq, int start, int end) {
        CharSequence cs = (csq == null ? "null" : csq);
        write(cs.subSequence(start, end).toString());
            return this;
    }
    

    I'm both pleased that this worked, and at the same time frustrated that it was so glaringly simple a fix that it took nearly a full week to figure out.

    I suppose the reason behind this error was likely a conflict in implementation. FoStringWriter extends StringWriter, but that itself extends Writer, and both classes have their own "append" methods that overwrite one another. By creating them explicitly, this error is resolved.