4

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.

Zibbobz
  • 725
  • 1
  • 15
  • 41
  • 1
    Is there any reason to make `FoStringWriter` a sub-class of `StringWriter`? Making it a subclass of `FilterWriter` which delegates to an arbitrary `Writer` (which *might* be a `StringWriter`) seems to be much more natural. And it might solve your compilation problem as a side-effect. – Holger Nov 19 '13 at 15:04
  • @Holger I've tried this as per your suggestion, but it seems to create an entirely different problem for me. Uncaught exception created in one of the service methods of the servlet action in application wpm. Exception created : javax.servlet.ServletException: java.lang.NoSuchMethodError: ny/dol/wpm/pdf/FoStringWriter.(Ljava/io/Writer;)V Note that I had to alter the call to FoStringWriter in other classes, because there is no constructor of FilterWrite that has no parameter, which is the way in which FoStringwriter was previously being called. I also had to add a (writer) constructor. – Zibbobz Nov 19 '13 at 15:50
  • 1
    The `NoSuchMethodError` indicates that not all classes have been updated correctly. By the way, it wouldn’t be so hard to add to add a default constructor to the new `FoStringWriter` which creates a `StringWriter` as target `Writer` and passes it to the super constructor. But the bigger problem is that the error says the constructor taking a writer has not been found so it’s the `FoStringWriter` class itself which has not been updated. – Holger Nov 19 '13 at 15:55
  • @Holger I'm having trouble implementing FilterWriter in my class. All the instances where FoStringWriter is called in my app have it calling a non-parameterized constructor, and FilterWriter does not include that constructor. Any tips you might be able to give me? – Zibbobz Nov 20 '13 at 17:38

1 Answers1

1

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.

Zibbobz
  • 725
  • 1
  • 15
  • 41