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:
@@ -64,18 +64,22 @@ public abstract class FieldMarshaller
|
|||||||
try {
|
try {
|
||||||
reader = field.getDeclaringClass().getMethod(
|
reader = field.getDeclaringClass().getMethod(
|
||||||
getReaderMethodName(field.getName()), READER_ARGS);
|
getReaderMethodName(field.getName()), READER_ARGS);
|
||||||
writer = field.getDeclaringClass().getMethod(
|
|
||||||
getWriterMethodName(field.getName()), WRITER_ARGS);
|
|
||||||
return new MethodFieldMarshaller(reader, writer);
|
|
||||||
} catch (NoSuchMethodException nsme) {
|
} catch (NoSuchMethodException nsme) {
|
||||||
// no problem
|
// no problem
|
||||||
}
|
}
|
||||||
// To get to this code path, either an exception was thrown when fetching reader or
|
try {
|
||||||
// when fetching writer... either way writer is guaranteed to be null.
|
writer = field.getDeclaringClass().getMethod(
|
||||||
if (reader != null) {
|
getWriterMethodName(field.getName()), WRITER_ARGS);
|
||||||
log.warning("Class contains a custom field reader, but not a writer",
|
} catch (NoSuchMethodException nsme) {
|
||||||
"class", field.getDeclaringClass().getName(), "field", field.getName(),
|
// no problem
|
||||||
"reader", reader);
|
}
|
||||||
|
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...
|
// fall through to using reflection on the fields...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user