Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
Issue checkstyle#4490: fix pmd violations for LoggerIsNotStaticFinal
Browse files Browse the repository at this point in the history
  • Loading branch information
vasylieva committed Jun 23, 2017
1 parent 2e4b3be commit ddbe4a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 0 additions & 2 deletions config/pmd-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
<exclude name="ConfusingTernary"/>
<!--till #4494-->
<exclude name="AppendCharacterWithChar"/>
<!--till #4490-->
<exclude name="LoggerIsNotStaticFinal"/>
<!--till #4489-->
<exclude name="JUnit4TestShouldUseTestAnnotation"/>
<!--till #4498-->
Expand Down
20 changes: 8 additions & 12 deletions src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public class MainTest {
+ " -x,--exclude-regexp <arg> Regular expression of directory to exclude from"
+ " CheckStyle%n");

private static Logger logger;
private static Handler[] handlers;
private static Level originalLogLevel;
private static final Logger LOG = Logger.getLogger(MainTest.class.getName()).getParent();
private static final Handler[] HANDLERS = LOG.getHandlers();
private static final Level ORIGINAL_LOG_LEVEL = LOG.getLevel();

@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
Expand Down Expand Up @@ -109,30 +109,26 @@ public static void init() {
// Set locale to root to prevent check message fail
// in other language environment.
Locale.setDefault(Locale.ROOT);

logger = Logger.getLogger(MainTest.class.getName()).getParent();
handlers = logger.getHandlers();
originalLogLevel = logger.getLevel();
}

@Before
public void setUp() {
// restore original logging level and handlers to prevent bleeding into other tests
// restore original logging level and HANDLERS to prevent bleeding into other tests

logger.setLevel(originalLogLevel);
LOG.setLevel(ORIGINAL_LOG_LEVEL);

for (Handler handler : logger.getHandlers()) {
for (Handler handler : LOG.getHandlers()) {
boolean found = false;

for (Handler savedHandler : handlers) {
for (Handler savedHandler : HANDLERS) {
if (handler == savedHandler) {
found = true;
break;
}
}

if (!found) {
logger.removeHandler(handler);
LOG.removeHandler(handler);
}
}
}
Expand Down

0 comments on commit ddbe4a4

Please sign in to comment.