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.
Related posts:
- Art of amazing object programming!
- Project Rescue Report
- Self Documenting Code Example
- More Fluent Interfaces in Test
- Three common ways of reusing behavior/code in OO
This entry was posted
on Tuesday, March 3rd, 2009 at 11:52 AM and is filed under Agile, Coaching, Programming.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.