diff options
author | Yigit Boyar <yboyar@google.com> | 2018-09-24 22:23:49 -0700 |
---|---|---|
committer | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-09-27 21:25:18 +0000 |
commit | d1bd820344c2bd5d4c5e7a1900d192aa711c09f1 (patch) | |
tree | ce99c7be2a98ea23e50c3fed07a7559edce1c957 /compiler/src/main/java/android/databinding | |
parent | ed52ed7ac98d51e9d6ec04ee327828ed591fe567 (diff) | |
download | data-binding-d1bd820344c2bd5d4c5e7a1900d192aa711c09f1.tar.gz |
Null check class analyzer calls
This is a quick fix to null check class anayzer
results to avoid NPE while traversing adapters.
It is tricky to test since this only happens with
a dependency that was both compiled with android.support
and pre 3.2 version. This is why I've added LibCompiledWith3.1
to the list of integration tests which is compiled manually
and the final aar is put under MultiModuleTestApp/app/libs.
Bug: 116361870
Test: MultiModuleTestApp
Change-Id: Ibaf6174980de08d50b0ef1b9679db6cf99e1121a
Diffstat (limited to 'compiler/src/main/java/android/databinding')
-rw-r--r-- | compiler/src/main/java/android/databinding/tool/store/SetterStore.java | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/compiler/src/main/java/android/databinding/tool/store/SetterStore.java b/compiler/src/main/java/android/databinding/tool/store/SetterStore.java index 2782c8e6..7ec8f010 100644 --- a/compiler/src/main/java/android/databinding/tool/store/SetterStore.java +++ b/compiler/src/main/java/android/databinding/tool/store/SetterStore.java @@ -495,6 +495,9 @@ public class SetterStore { return null; } ModelClass viewClass = mClassAnalyzer.findClass(adapter.viewType, null); + if (viewClass == null) { + return null; + } if (viewClass.isGeneric()) { viewClass = viewClass.erasure(); } @@ -518,8 +521,11 @@ public class SetterStore { supplied[index] = true; matchingAttributes++; final String parameterTypeStr = adapter.parameterTypes[index]; - final ModelClass parameterType = eraseType( - mClassAnalyzer.findClass(parameterTypeStr, null)); + ModelClass paramClass = mClassAnalyzer.findClass(parameterTypeStr, null); + if (paramClass == null) { + return null; + } + final ModelClass parameterType = eraseType(paramClass); final ModelClass attributeType = attributeValues[i]; if (!parameterType.isAssignableFrom(attributeType)) { if (ModelMethod.isBoxingConversion(parameterType, attributeType)) { @@ -713,6 +719,9 @@ public class SetterStore { List<String> setterCandidates = mStore.findRenamed(attribute, className -> { try { ModelClass renamedViewType = mClassAnalyzer.findClass(className, imports); + if (renamedViewType == null) { + return false; + } return renamedViewType.erasure().isAssignableFrom(finalViewType); } catch (Exception e) { //printMessage(Diagnostic.Kind.NOTE, "Unknown class: " + className); @@ -769,7 +778,8 @@ public class SetterStore { mStore.forEachInverseMethod(attribute, (className, inverseDescription) -> { try { ModelClass methodViewType = mClassAnalyzer.findClass(className, imports); - if (methodViewType.erasure().isAssignableFrom(finalViewType)) { + if (methodViewType != null + && methodViewType.erasure().isAssignableFrom(finalViewType)) { final String name = inverseDescription.method.isEmpty() ? trimAttributeNamespace(attribute) : inverseDescription.method; ModelMethod method = methodViewType.findInstanceGetter(name); @@ -1008,12 +1018,13 @@ public class SetterStore { return mStore.findFirstConversionMethod((fromClassName, conversion) -> { try { ModelClass convertFrom = mClassAnalyzer.findClass(fromClassName, imports); - if (canUseForConversion(from, convertFrom)) { + if (convertFrom != null && canUseForConversion(from, convertFrom)) { for (String toClassName : conversion.keySet()) { try { - ModelClass convertTo = mClassAnalyzer.findClass(toClassName, - imports); - if (canUseForConversion(convertTo, to)) { + ModelClass convertTo = mClassAnalyzer + .findClass(toClassName, imports); + if (convertTo != null + && canUseForConversion(convertTo, to)) { return conversion.get(toClassName); } } catch (Exception e) { |