From c62b8de182b5a635b4eb80d036d1c264a5a178fa Mon Sep 17 00:00:00 2001 From: Damien Date: Thu, 6 Jun 2013 19:48:33 +0200 Subject: [PATCH 1/2] Fix a NullPointerException throwing during refactoring. Let the compiler inform the developer about the missing constant --- .../androidannotations/helper/AnnotationHelper.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/AnnotationHelper.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/AnnotationHelper.java index 9530be82b6..1e3951adad 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/AnnotationHelper.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/AnnotationHelper.java @@ -255,6 +255,12 @@ public String[] extractAnnotationResNameParameter(Element element, String annota * Annotation resName() parameter can be a String or a String[] */ Object annotationResName = extractAnnotationParameter(element, annotationName, "resName"); + if (annotationResName == null) { + // This case happened during refactoring, if the id has been changed + // in the layout and compiler throws an error on the annotation + // because the constant doesn't exists anymore + return new String[0]; + } String[] resNames; if (annotationResName.getClass().isArray()) { @@ -271,6 +277,12 @@ public int[] extractAnnotationResIdValueParameter(Element element, String annota * Annotation value() parameter can be an int or an int[] */ Object annotationValue = extractAnnotationParameter(element, annotationName, "value"); + if (annotationValue == null) { + // This case happened during refactoring, if the id has been changed + // in the layout and compiler throws an error on the annotation + // because the constant doesn't exists anymore + return new int[0]; + } int[] values; if (annotationValue.getClass().isArray()) { From f9c01054869297c32f81af61d6d15a5294aa8b75 Mon Sep 17 00:00:00 2001 From: Damien Date: Fri, 20 Sep 2013 17:20:48 +0200 Subject: [PATCH 2/2] Add a check on idsRefs of AbstractListenerProcessor to get ride of NPE if resources id doesn't exists --- .../processing/AbstractListenerProcessor.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/AbstractListenerProcessor.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/AbstractListenerProcessor.java index 8e0070fc8c..bf182239bd 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/AbstractListenerProcessor.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/AbstractListenerProcessor.java @@ -80,12 +80,13 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) { processParameters(listenerMethod, call, parameters); for (JFieldRef idRef : idsRefs) { - ViewChangedHolder onViewChanged = holder.onViewChanged(); + if (idRef != null) { + ViewChangedHolder onViewChanged = holder.onViewChanged(); - JBlock block = onViewChanged.body().block(); - JInvocation view = onViewChanged.findViewById(idRef); - - block._if(view.ne(_null()))._then().invoke(castWidget(view), getSetterName()).arg(_new(listenerAnonymousClass)); + JBlock block = onViewChanged.body().block(); + JInvocation view = onViewChanged.findViewById(idRef); + block._if(view.ne(_null()))._then().invoke(castWidget(view), getSetterName()).arg(_new(listenerAnonymousClass)); + } } }