Skip to content

Commit

Permalink
Fix crash from empty list (#1249)
Browse files Browse the repository at this point in the history
  • Loading branch information
elihart authored Nov 10, 2021
1 parent 687c845 commit ab8ce37
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,12 @@ class Memoizer(

viewModelAnnotations.forEach { annotation ->
superViewElement.getElementsAnnotatedWith(annotation).forEach { element ->
val isPackagePrivate by lazy { Utils.isFieldPackagePrivate(element) }
annotatedElements
.getOrPut(annotation) { mutableListOf() }
.add(
ViewElement(
element = element,
isPackagePrivate = isPackagePrivate,
isPackagePrivate = Utils.isFieldPackagePrivate(element),
attributeInfo = lazy {
ViewAttributeInfo(
viewElement = superViewElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,14 @@ class ModelViewProcessor @JvmOverloads constructor(
// We don't want the attribute from the super class replacing an attribute in the
// subclass if the subclass overrides it, since the subclass definition could include
// different annotation parameter settings, or we could end up with duplicates

// If an annotated prop method has a default value it will also have @JvmOverloads
// so java source in KAPT sees both a zero param and and 1 param method. We just
// ignore the empty param version.
if (it.element is XMethodElement && it.element.parameters.size != 1) {
return@forEachElementWithAnnotation
}

view.addAttributeIfNotExists(it.attributeInfo.value)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ open class BaseView(context: Context) : View(context) {
@ModelProp
fun baseViewProp(prop: Int) {
}

@JvmOverloads
@ModelProp
fun baseViewPropWithDefaultParamValue(prop: Int = 0) {
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ SourceViewModelBuilder onVisibilityChanged(

SourceViewModelBuilder baseViewProp(int baseViewProp);

SourceViewModelBuilder baseViewPropWithDefaultParamValue(int baseViewPropWithDefaultParamValue);

SourceViewModelBuilder showDividerWithSetter(Boolean showDividerWithSetter);

SourceViewModelBuilder showDividerWithOverriddenMethod(boolean showDivider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class SourceViewModel_ extends AirEpoxyModel<SourceView> implements Gener

private int baseViewProp_Int = 0;

private int baseViewPropWithDefaultParamValue_Int = 0;

public SourceViewModel_() {
super();
}
Expand Down Expand Up @@ -60,6 +62,7 @@ public void handlePreBind(final EpoxyViewHolder holder, final SourceView object,
public void bind(final SourceView object) {
super.bind(object);
object.setSectionId(sectionId_String);
object.baseViewPropWithDefaultParamValue(baseViewPropWithDefaultParamValue_Int);
object.baseViewProp(baseViewProp_Int);
}

Expand All @@ -76,6 +79,10 @@ public void bind(final SourceView object, EpoxyModel previousModel) {
object.setSectionId(sectionId_String);
}

if ((baseViewPropWithDefaultParamValue_Int != that.baseViewPropWithDefaultParamValue_Int)) {
object.baseViewPropWithDefaultParamValue(baseViewPropWithDefaultParamValue_Int);
}

if ((baseViewProp_Int != that.baseViewProp_Int)) {
object.baseViewProp(baseViewProp_Int);
}
Expand Down Expand Up @@ -199,6 +206,21 @@ public int baseViewProp() {
return baseViewProp_Int;
}

/**
* <i>Optional</i>: Default value is 0
*
* @see BaseView#baseViewPropWithDefaultParamValue(int)
*/
public SourceViewModel_ baseViewPropWithDefaultParamValue(int baseViewPropWithDefaultParamValue) {
onMutation();
this.baseViewPropWithDefaultParamValue_Int = baseViewPropWithDefaultParamValue;
return this;
}

public int baseViewPropWithDefaultParamValue() {
return baseViewPropWithDefaultParamValue_Int;
}

public SourceViewModel_ showDividerWithSetter(Boolean showDividerWithSetter) {
onMutation();
super.setShowDividerWithSetter(showDividerWithSetter);
Expand Down Expand Up @@ -302,6 +324,7 @@ public SourceViewModel_ reset() {
onModelVisibilityChangedListener_epoxyGeneratedModel = null;
this.sectionId_String = (String) null;
this.baseViewProp_Int = 0;
this.baseViewPropWithDefaultParamValue_Int = 0;
super.setShowDivider(null);
super.setShowDividerWithSetter(null);
super.reset();
Expand Down Expand Up @@ -338,6 +361,9 @@ public boolean equals(Object o) {
if ((baseViewProp_Int != that.baseViewProp_Int)) {
return false;
}
if ((baseViewPropWithDefaultParamValue_Int != that.baseViewPropWithDefaultParamValue_Int)) {
return false;
}
if ((getShowDivider() != null ? !getShowDivider().equals(that.getShowDivider()) : that.getShowDivider() != null)) {
return false;
}
Expand All @@ -356,6 +382,7 @@ public int hashCode() {
_result = 31 * _result + (onModelVisibilityChangedListener_epoxyGeneratedModel != null ? 1 : 0);
_result = 31 * _result + (sectionId_String != null ? sectionId_String.hashCode() : 0);
_result = 31 * _result + baseViewProp_Int;
_result = 31 * _result + baseViewPropWithDefaultParamValue_Int;
_result = 31 * _result + (getShowDivider() != null ? getShowDivider().hashCode() : 0);
_result = 31 * _result + (getShowDividerWithSetter() != null ? getShowDividerWithSetter().hashCode() : 0);
return _result;
Expand All @@ -366,6 +393,7 @@ public String toString() {
return "SourceViewModel_{" +
"sectionId_String=" + sectionId_String +
", baseViewProp_Int=" + baseViewProp_Int +
", baseViewPropWithDefaultParamValue_Int=" + baseViewPropWithDefaultParamValue_Int +
", showDivider=" + getShowDivider() +
", showDividerWithSetter=" + getShowDividerWithSetter() +
"}" + super.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ SourceViewModelBuilder onVisibilityChanged(

SourceViewModelBuilder baseViewProp(int baseViewProp);

SourceViewModelBuilder baseViewPropWithDefaultParamValue(int baseViewPropWithDefaultParamValue);

SourceViewModelBuilder showDividerWithSetter(@Nullable Boolean showDividerWithSetter);

SourceViewModelBuilder showDividerWithOverriddenMethod(boolean showDivider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class SourceViewModel_ extends AirEpoxyModel<SourceView> implements Gener

private int baseViewProp_Int = 0;

private int baseViewPropWithDefaultParamValue_Int = 0;

public SourceViewModel_() {
super();
}
Expand Down Expand Up @@ -60,6 +62,7 @@ public void handlePreBind(final EpoxyViewHolder holder, final SourceView object,
public void bind(final SourceView object) {
super.bind(object);
object.setSectionId(sectionId_String);
object.baseViewPropWithDefaultParamValue(baseViewPropWithDefaultParamValue_Int);
object.baseViewProp(baseViewProp_Int);
}

Expand All @@ -76,6 +79,10 @@ public void bind(final SourceView object, EpoxyModel previousModel) {
object.setSectionId(sectionId_String);
}

if ((baseViewPropWithDefaultParamValue_Int != that.baseViewPropWithDefaultParamValue_Int)) {
object.baseViewPropWithDefaultParamValue(baseViewPropWithDefaultParamValue_Int);
}

if ((baseViewProp_Int != that.baseViewProp_Int)) {
object.baseViewProp(baseViewProp_Int);
}
Expand Down Expand Up @@ -199,6 +206,21 @@ public int baseViewProp() {
return baseViewProp_Int;
}

/**
* <i>Optional</i>: Default value is 0
*
* @see BaseView#baseViewPropWithDefaultParamValue(int)
*/
public SourceViewModel_ baseViewPropWithDefaultParamValue(int baseViewPropWithDefaultParamValue) {
onMutation();
this.baseViewPropWithDefaultParamValue_Int = baseViewPropWithDefaultParamValue;
return this;
}

public int baseViewPropWithDefaultParamValue() {
return baseViewPropWithDefaultParamValue_Int;
}

public SourceViewModel_ showDividerWithSetter(@Nullable Boolean showDividerWithSetter) {
onMutation();
super.setShowDividerWithSetter(showDividerWithSetter);
Expand Down Expand Up @@ -301,6 +323,7 @@ public SourceViewModel_ reset() {
onModelVisibilityChangedListener_epoxyGeneratedModel = null;
this.sectionId_String = (String) null;
this.baseViewProp_Int = 0;
this.baseViewPropWithDefaultParamValue_Int = 0;
super.setShowDivider(null);
super.setShowDividerWithSetter(null);
super.reset();
Expand Down Expand Up @@ -337,6 +360,9 @@ public boolean equals(Object o) {
if ((baseViewProp_Int != that.baseViewProp_Int)) {
return false;
}
if ((baseViewPropWithDefaultParamValue_Int != that.baseViewPropWithDefaultParamValue_Int)) {
return false;
}
if ((getShowDivider() != null ? !getShowDivider().equals(that.getShowDivider()) : that.getShowDivider() != null)) {
return false;
}
Expand All @@ -355,6 +381,7 @@ public int hashCode() {
_result = 31 * _result + (onModelVisibilityChangedListener_epoxyGeneratedModel != null ? 1 : 0);
_result = 31 * _result + (sectionId_String != null ? sectionId_String.hashCode() : 0);
_result = 31 * _result + baseViewProp_Int;
_result = 31 * _result + baseViewPropWithDefaultParamValue_Int;
_result = 31 * _result + (getShowDivider() != null ? getShowDivider().hashCode() : 0);
_result = 31 * _result + (getShowDividerWithSetter() != null ? getShowDividerWithSetter().hashCode() : 0);
return _result;
Expand All @@ -365,6 +392,7 @@ public String toString() {
return "SourceViewModel_{" +
"sectionId_String=" + sectionId_String +
", baseViewProp_Int=" + baseViewProp_Int +
", baseViewPropWithDefaultParamValue_Int=" + baseViewPropWithDefaultParamValue_Int +
", showDivider=" + getShowDivider() +
", showDividerWithSetter=" + getShowDividerWithSetter() +
"}" + super.toString();
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=5.0.0-beta02
VERSION_NAME=5.0.0-beta03
GROUP=com.airbnb.android
POM_DESCRIPTION=Epoxy is a system for composing complex screens with a ReyclerView in Android.
POM_URL=https://github.com/airbnb/epoxy
Expand Down

0 comments on commit ab8ce37

Please sign in to comment.