Check for null parent references to prevent crash

- fixes #745
This commit is contained in:
Connor Tumbleson 2016-08-06 12:46:45 -04:00
parent bada6441ec
commit 00abedfa06
No known key found for this signature in database
GPG Key ID: C3CC0A201EC7DA75
2 changed files with 14 additions and 2 deletions

View File

@ -17,6 +17,7 @@
package brut.androlib.res.data.value;
import brut.androlib.AndrolibException;
import brut.androlib.err.UndefinedResObject;
import brut.androlib.res.data.ResPackage;
import brut.androlib.res.data.ResResSpec;
@ -45,6 +46,9 @@ public class ResReferenceValue extends ResIntValue {
}
ResResSpec spec = getReferent();
if (spec == null) {
return "@null";
}
boolean newId = spec.hasDefaultResource() && spec.getDefaultResource().getValue() instanceof ResIdValue;
// generate the beginning to fix @android
@ -54,10 +58,18 @@ public class ResReferenceValue extends ResIntValue {
}
public ResResSpec getReferent() throws AndrolibException {
return mPackage.getResTable().getResSpec(getValue());
try {
return mPackage.getResTable().getResSpec(getValue());
} catch (UndefinedResObject ex) {
return null;
}
}
public boolean isNull() {
return mValue == 0;
}
public boolean referentIsNull() throws AndrolibException {
return getReferent() == null;
}
}

View File

@ -45,7 +45,7 @@ public class ResStyleValue extends ResBagValue implements
ResResource res) throws IOException, AndrolibException {
serializer.startTag(null, "style");
serializer.attribute(null, "name", res.getResSpec().getName());
if (!mParent.isNull()) {
if (!mParent.isNull() && !mParent.referentIsNull()) {
serializer.attribute(null, "parent", mParent.encodeAsResXmlAttr());
} else if (res.getResSpec().getName().indexOf('.') != -1) {
serializer.attribute(null, "parent", "");