am b3cfb334: Merge "Fix rare NPE in BridgeContext." into lmp-mr1-dev

* commit 'b3cfb334893a0b302cd6a0a998f27ca2e8ba7f9d':
  Fix rare NPE in BridgeContext.
This commit is contained in:
Deepanshu Gupta
2015-03-12 00:39:25 +00:00
committed by Android Git Automerger

View File

@ -94,6 +94,7 @@ import java.util.Map;
/** /**
* Custom implementation of Context/Activity to handle non compiled resources. * Custom implementation of Context/Activity to handle non compiled resources.
*/ */
@SuppressWarnings("deprecation") // For use of Pair.
public final class BridgeContext extends Context { public final class BridgeContext extends Context {
/** The map adds cookies to each view so that IDE can link xml tags to views. */ /** The map adds cookies to each view so that IDE can link xml tags to views. */
@ -569,7 +570,7 @@ public final class BridgeContext extends Context {
// Hint: for XmlPullParser, attach source //DEVICE_SRC/dalvik/libcore/xml/src/java // Hint: for XmlPullParser, attach source //DEVICE_SRC/dalvik/libcore/xml/src/java
if (set instanceof BridgeXmlBlockParser) { if (set instanceof BridgeXmlBlockParser) {
BridgeXmlBlockParser parser = null; BridgeXmlBlockParser parser;
parser = (BridgeXmlBlockParser)set; parser = (BridgeXmlBlockParser)set;
isPlatformFile = parser.isPlatformFile(); isPlatformFile = parser.isPlatformFile();
@ -590,7 +591,7 @@ public final class BridgeContext extends Context {
} else if (set != null) { // null parser is ok } else if (set != null) { // null parser is ok
// really this should not be happening since its instantiated in Bridge // really this should not be happening since its instantiated in Bridge
Bridge.getLog().error(LayoutLog.TAG_BROKEN, Bridge.getLog().error(LayoutLog.TAG_BROKEN,
"Parser is not a BridgeXmlBlockParser!", null /*data*/); "Parser is not a BridgeXmlBlockParser!", null);
return null; return null;
} }
@ -602,7 +603,7 @@ public final class BridgeContext extends Context {
// look for a custom style. // look for a custom style.
String customStyle = null; String customStyle = null;
if (set != null) { if (set != null) {
customStyle = set.getAttributeValue(null /* namespace*/, "style"); customStyle = set.getAttributeValue(null, "style");
} }
StyleResourceValue customStyleValues = null; StyleResourceValue customStyleValues = null;
@ -625,6 +626,13 @@ public final class BridgeContext extends Context {
// get the name from the int. // get the name from the int.
Pair<String, Boolean> defStyleAttribute = searchAttr(defStyleAttr); Pair<String, Boolean> defStyleAttribute = searchAttr(defStyleAttr);
if (defStyleAttribute == null) {
// This should be rare. Happens trying to map R.style.foo to @style/foo fails.
// This will happen if the user explicitly used a non existing int value for
// defStyleAttr or there's something wrong with the project structure/build.
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE,
"Failed to find the style corresponding to the id " + defStyleAttr, null);
} else {
if (defaultPropMap != null) { if (defaultPropMap != null) {
String defStyleName = defStyleAttribute.getFirst(); String defStyleName = defStyleAttribute.getFirst();
if (defStyleAttribute.getSecond()) { if (defStyleAttribute.getSecond()) {
@ -642,14 +650,15 @@ public final class BridgeContext extends Context {
item = mRenderResources.findResValue(item.getValue(), item.isFramework()); item = mRenderResources.findResValue(item.getValue(), item.isFramework());
if (item instanceof StyleResourceValue) { if (item instanceof StyleResourceValue) {
defStyleValues = (StyleResourceValue)item; defStyleValues = (StyleResourceValue) item;
} }
} else { } else {
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE_THEME_ATTR, Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE_THEME_ATTR,
String.format( String.format(
"Failed to find style '%s' in current theme", "Failed to find style '%s' in current theme",
defStyleAttribute.getFirst()), defStyleAttribute.getFirst()),
null /*data*/); null);
}
} }
} else if (defStyleRes != 0) { } else if (defStyleRes != 0) {
boolean isFrameworkRes = true; boolean isFrameworkRes = true;