Open BlackHornet opened 9 years ago
As for your last point, shouldn't it be
if (field != null) {
field.set(this, value);
}
Your proposed change wouldn't work because field
is null if columnIsNull == true
.
no, I set value = null if columnIsNull
And for your point: in that case it would crash earlier anyway in
field.setAccessible(true);
That is not the case:
for (Field field : mTableInfo.getFields()) {
final String fieldName = mTableInfo.getColumnName(field);
Class<?> fieldType = field.getType();
final int columnIndex = columnsOrdered.indexOf(fieldName);
if (columnIndex < 0) {
continue;
}
field.setAccessible(true);
try {
boolean columnIsNull = cursor.isNull(columnIndex);
TypeSerializer typeSerializer = Cache.getParserForType(fieldType);
Object value = null;
if (typeSerializer != null) {
fieldType = typeSerializer.getSerializedType();
}
if (columnIsNull) {
field = null; // NOTE: Field is set as null
}
[...]
// Set the field value
if (field != null) { // NOTE: This was changed
field.set(this, value);
}
}
}
The comments with NOTE
are mine.
But as I said...instead it should be:
if (columnIsNull) {
value = null;
}
[...]
// Set the field value
field.set(this, value);
:)
It don't make any sense to set field null if the cursor VALUE for a field is null...
I'm not sure if this is a compilation error or whatever, but when checking the decompiled loadFromCursor there is a HUGE mismatch between code and compilation.
this is java source:
This is compiled Model.class (in my bytecode version 50.0 (Java 6)):
be aware of the total crappy while(true)...do-while with return if mId != null
In my situation where I don't use any joins, i have to comment
to fix the compilation issue...after commenting these line the compilation looks fine again! I'm not sure if this a local issue with the used Java compiler, but in case this has to be checked if #106 was applied wrong here.
In addition there is a HUGE error in that code, where existing entities field won't set NULL if the field value in the cursor is NULL:
This WON'T change anything, instead it should be:
This ensures if a field changes to NULL this is propagated to the entity too.