Skip to content

Commit

Permalink
Merge branch '2.3.x' into 2.4.x
Browse files Browse the repository at this point in the history
Closes gh-26322
  • Loading branch information
snicoll committed Apr 30, 2021
2 parents 63d4861 + 1af7fa2 commit 4ccce2a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -70,11 +70,12 @@ private String buildMessage(DependencyCycle dependencyCycle) {
message.append(
String.format("The dependencies of some of the beans in the application context form a cycle:%n%n"));
List<BeanInCycle> beansInCycle = dependencyCycle.getBeansInCycle();
boolean singleBean = beansInCycle.size() == 1;
int cycleStart = dependencyCycle.getCycleStart();
for (int i = 0; i < beansInCycle.size(); i++) {
BeanInCycle beanInCycle = beansInCycle.get(i);
if (i == cycleStart) {
message.append(String.format("┌─────┐%n"));
message.append(String.format(singleBean ? "┌──->──┐%n" : "┌─────┐%n"));
}
else if (i > 0) {
String leftSide = (i < cycleStart) ? " " : "↑";
Expand All @@ -83,7 +84,7 @@ else if (i > 0) {
String leftSide = (i < cycleStart) ? " " : "|";
message.append(String.format("%s %s%n", leftSide, beanInCycle));
}
message.append(String.format("└─────┘%n"));
message.append(String.format(singleBean ? "└──<-──┘%n" : "└─────┘%n"));
return message.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -109,6 +109,19 @@ void cycleReferencedViaOtherBeans() throws IOException {
assertThat(lines.get(11)).isEqualTo("└─────┘");
}

@Test
void testSelfReferenceCycle() throws IOException {
FailureAnalysis analysis = performAnalysis(SelfReferenceBeanConfiguration.class);
List<String> lines = readDescriptionLines(analysis);
assertThat(lines).hasSize(5);
assertThat(lines.get(0))
.isEqualTo("The dependencies of some of the beans in the application context form a cycle:");
assertThat(lines.get(1)).isEqualTo("");
assertThat(lines.get(2)).isEqualTo("┌──->──┐");
assertThat(lines.get(3)).startsWith("| bean defined in " + SelfReferenceBeanConfiguration.class.getName());
assertThat(lines.get(4)).isEqualTo("└──<-──┘");
}

@Test
void cycleWithAnUnknownStartIsNotAnalyzed() {
assertThat(this.analyzer.analyze(new BeanCurrentlyInCreationException("test"))).isNull();
Expand Down Expand Up @@ -240,6 +253,16 @@ BeanThree three(BeanOne one) {

}

@Configuration(proxyBeanMethods = false)
static class SelfReferenceBeanConfiguration {

@Bean
SelfReferenceBean bean(SelfReferenceBean bean) {
return new SelfReferenceBean();
}

}

static class RefererOne {

@Autowired
Expand All @@ -266,4 +289,11 @@ static class BeanThree {

}

static class SelfReferenceBean {

@Autowired
SelfReferenceBean bean;

}

}

0 comments on commit 4ccce2a

Please sign in to comment.