XNSIO
  About   Slides   Home  

 
Managed Chaos
Naresh Jain's Random Thoughts on Software Development and Adventure Sports
     
`
 
RSS Feed
Recent Thoughts
Tags
Recent Comments

Checkstyle’s Strict Duplicate Code Check Rocks!

Recently, during a project rescue effort, I introduced Checkstyle as part of the automated build. This morning I saw the build failing because of the following Checkstyle violation:

File: SuccessEvent.java, Line: 10, Type: StrictDuplicateCodeCheck, Priority: High, Category: Duplicates
Found duplicate of 14 lines in AcceptEvent.java, starting from line 10

When I checked the source code of the 2 files, this is what I found:

1
2
public class SuccessEvent extends EngineEvent {
    private final Document document;
1
2
3
    public SuccessEvent(final Document document) {
        this.document = document;
    }
1
2
3
4
    @Override
    Document getDocument() {
        return document;
    }
1
2
3
4
5
    @Override
    String getMessage() {
        return "";
    }
}
1
2
public class AcceptEvent extends EngineEvent {
    private final Document document;
1
2
3
    public AcceptEvent(final Document document) {
        this.document = document;
    }
1
2
3
4
    @Override
    Document getDocument() {
        return document;
    }
1
2
3
4
5
    @Override
    String getMessage() {
        return "";
    }
}

As you can see, except the name of the class, the 2 files are identical. On one hand I’m thrilled that Checkstyle does a great job at catching such errors, on other hand I’m sad that there are developers who write such sloppy code.


    Licensed under
Creative Commons License