Skip to content

Commit 6998e81

Browse files
committed
add NoAutoStartUtil.shouldBeStarted method
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
1 parent 40bc1c2 commit 6998e81

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

logback-core/src/main/java/ch/qos/logback/core/joran/spi/NoAutoStartUtil.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*/
1414
package ch.qos.logback.core.joran.spi;
1515

16+
import ch.qos.logback.core.spi.LifeCycle;
17+
1618
public class NoAutoStartUtil {
1719

1820
/**
@@ -23,12 +25,23 @@ public class NoAutoStartUtil {
2325
* @return true for classes not marked with the NoAutoStart annotation
2426
*/
2527
static public boolean notMarkedWithNoAutoStart(Object o) {
26-
if (o == null) {
27-
return false;
28-
}
2928
Class<?> clazz = o.getClass();
3029
NoAutoStart a = clazz.getAnnotation(NoAutoStart.class);
3130
return a == null;
3231
}
3332

33+
/**
34+
* Is the object a {@link LifeCycle} and is it marked not marked with
35+
* the NoAutoStart annotation.
36+
* @param o
37+
* @return
38+
* @ since 1.5.2
39+
*/
40+
static public boolean shouldBeStarted(Object o) {
41+
if(o instanceof LifeCycle) {
42+
return notMarkedWithNoAutoStart(o);
43+
} else
44+
return false;
45+
}
46+
3447
}

logback-core/src/main/java/ch/qos/logback/core/model/processor/ImplicitModelHandler.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ private void postHandleComplex(ModelInterpretationContext mic, Model model,
203203
// start the nested complex property if it implements LifeCycle and is not
204204
// marked with a @NoAutoStart annotation
205205
Object nestedComplexProperty = imdComplex.getNestedComplexProperty();
206-
if (nestedComplexProperty instanceof LifeCycle
207-
&& NoAutoStartUtil.notMarkedWithNoAutoStart(nestedComplexProperty)) {
206+
if (NoAutoStartUtil.shouldBeStarted(nestedComplexProperty)) {
208207
((LifeCycle) nestedComplexProperty).start();
209208
}
210209

0 commit comments

Comments
 (0)