Actually Eclipse was telling us something useful. The point of that code was to

issue a warning if someone created a reader method or a writer method but not
both. Eclipse's static analysis helpfully pointed out that we'll never know if
someone fails to declare a reader but does declare a writer because of the way
method lookup fails. Since we want to actually detect that situation and
generate a helpful warnings, we restructure the code so that the static
analyzer is happy and developers asses are covered.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5286 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2008-08-04 18:09:55 +00:00
parent 1fafa17293
commit 93cffda93f
@@ -64,18 +64,22 @@ public abstract class FieldMarshaller
try {
reader = field.getDeclaringClass().getMethod(
getReaderMethodName(field.getName()), READER_ARGS);
writer = field.getDeclaringClass().getMethod(
getWriterMethodName(field.getName()), WRITER_ARGS);
return new MethodFieldMarshaller(reader, writer);
} catch (NoSuchMethodException nsme) {
// no problem
}
// To get to this code path, either an exception was thrown when fetching reader or
// when fetching writer... either way writer is guaranteed to be null.
if (reader != null) {
log.warning("Class contains a custom field reader, but not a writer",
"class", field.getDeclaringClass().getName(), "field", field.getName(),
"reader", reader);
try {
writer = field.getDeclaringClass().getMethod(
getWriterMethodName(field.getName()), WRITER_ARGS);
} catch (NoSuchMethodException nsme) {
// no problem
}
if (reader != null && writer != null) {
return new MethodFieldMarshaller(reader, writer);
}
if (reader == null || writer == null) {
log.warning("Class contains one but not both custom field reader and writer" +
"class", field.getDeclaringClass().getName(), "field=", field.getName(),
"reader", reader, "writer", writer);
// fall through to using reflection on the fields...
}
}