diff options
| author | Deepanshu Gupta <deepanshu@google.com> | 2015-03-13 06:32:49 +0000 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2015-03-13 06:32:49 +0000 |
| commit | 1bbb9e1d5d6c5620cf5da3309159620c74f64cd1 (patch) | |
| tree | 5328a4619925d2476cebdc614e175f9c29391181 /tools | |
| parent | cfed1b5222d6889312cfa8b7226fb07effd06297 (diff) | |
| parent | fceec0e124a55b25d59f2af5279c70ac045d6771 (diff) | |
| download | frameworks_base-1bbb9e1d5d6c5620cf5da3309159620c74f64cd1.zip frameworks_base-1bbb9e1d5d6c5620cf5da3309159620c74f64cd1.tar.gz frameworks_base-1bbb9e1d5d6c5620cf5da3309159620c74f64cd1.tar.bz2 | |
am fceec0e1: am c7fc094d: am d44af610: am b3cfb334: Merge "Fix rare NPE in BridgeContext." into lmp-mr1-dev
* commit 'fceec0e124a55b25d59f2af5279c70ac045d6771':
Fix rare NPE in BridgeContext.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java index d88a867..bcd9633 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java @@ -96,6 +96,7 @@ import java.util.Map; /** * Custom implementation of Context/Activity to handle non compiled resources. */ +@SuppressWarnings("deprecation") // For use of Pair. public final class BridgeContext extends Context { /** The map adds cookies to each view so that IDE can link xml tags to views. */ @@ -599,7 +600,7 @@ public final class BridgeContext extends Context { // Hint: for XmlPullParser, attach source //DEVICE_SRC/dalvik/libcore/xml/src/java if (set instanceof BridgeXmlBlockParser) { - BridgeXmlBlockParser parser = null; + BridgeXmlBlockParser parser; parser = (BridgeXmlBlockParser)set; isPlatformFile = parser.isPlatformFile(); @@ -620,7 +621,7 @@ public final class BridgeContext extends Context { } else if (set != null) { // null parser is ok // really this should not be happening since its instantiated in Bridge Bridge.getLog().error(LayoutLog.TAG_BROKEN, - "Parser is not a BridgeXmlBlockParser!", null /*data*/); + "Parser is not a BridgeXmlBlockParser!", null); return null; } @@ -632,7 +633,7 @@ public final class BridgeContext extends Context { // look for a custom style. String customStyle = null; if (set != null) { - customStyle = set.getAttributeValue(null /* namespace*/, "style"); + customStyle = set.getAttributeValue(null, "style"); } StyleResourceValue customStyleValues = null; @@ -655,31 +656,39 @@ public final class BridgeContext extends Context { // get the name from the int. Pair<String, Boolean> defStyleAttribute = searchAttr(defStyleAttr); - if (defaultPropMap != null) { - String defStyleName = defStyleAttribute.getFirst(); - if (defStyleAttribute.getSecond()) { - defStyleName = "android:" + defStyleName; + 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) { + String defStyleName = defStyleAttribute.getFirst(); + if (defStyleAttribute.getSecond()) { + defStyleName = "android:" + defStyleName; + } + defaultPropMap.put("style", defStyleName); } - defaultPropMap.put("style", defStyleName); - } - // look for the style in the current theme, and its parent: - ResourceValue item = mRenderResources.findItemInTheme(defStyleAttribute.getFirst(), - defStyleAttribute.getSecond()); + // look for the style in the current theme, and its parent: + ResourceValue item = mRenderResources.findItemInTheme(defStyleAttribute.getFirst(), + defStyleAttribute.getSecond()); - if (item != null) { - // item is a reference to a style entry. Search for it. - item = mRenderResources.findResValue(item.getValue(), item.isFramework()); + if (item != null) { + // item is a reference to a style entry. Search for it. + item = mRenderResources.findResValue(item.getValue(), item.isFramework()); - if (item instanceof StyleResourceValue) { - defStyleValues = (StyleResourceValue)item; + if (item instanceof StyleResourceValue) { + defStyleValues = (StyleResourceValue) item; + } + } else { + Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE_THEME_ATTR, + String.format( + "Failed to find style '%s' in current theme", + defStyleAttribute.getFirst()), + null); } - } else { - Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE_THEME_ATTR, - String.format( - "Failed to find style '%s' in current theme", - defStyleAttribute.getFirst()), - null /*data*/); } } else if (defStyleRes != 0) { boolean isFrameworkRes = true; |
