Posts Tagged Checkstyle

My checkstyle regex mismatch

Checkstyle has a LineLength module.  This enables us to automatically give info messages if the code has extra long lines in it.  The LineLength module has an ignorePattern property for those long lines that are ok.  We were setting this to ignore javadoc comments with long links in them.

What it was before:

^.*@(see|link).*$

The Problem

The problem was, this regex did not match cases where the @link was on one line and the link had been formatted to the next line (as would happen sometimes when we use Eclipse’s Ctrl+Shift+F code formatter), so those still showed up as infos.

What I Want to Match

Zero or more whitespace characters,
followed by a literal ‘*’,
followed by zero or more whitespace characters,
optionally followed by ‘@see ‘ or ‘{@link ‘,
followed by one or more non-whitespace characters.

My Good-enough Solution

After messing around for quite a while, this is the regex I eventually put in place:

^.*\*.*((@see)|(\{@link) )?[^ \t]+$

Notice the .* after the initial ^ though: we’re matching on any character, not just whitespace.  I wanted to do something like this:

^\s*\*\s*((@see)|(\{@link) )?[^ \t]+$

Or this:

^[ \t]*\*[ \t]*((@see)|(\{@link) )?[^ \t]+$

But when I did that, the comment lines weren’t matched, and they still showed up as infos.

Why is that?

, , ,

Leave a comment

Reticent checkstyle

“Why, oh why are you failing my local build, Checkstyle?”

But Checkstyle just smiled demurely and shook her head…


I overheard an email conversation today that involved getting Checkstyle errors in Eclipse but it not being apparent what the errors were.  I thought I’d chronicle it here since it could be helpful again in the future…

Developer 1: “I just ran Maven Clean Install and if fails, saying I have 5 Checkstyle violations, but there are no warnings or errors in my Problems pane.  None of the packages in my project show any warnings or errors, either.”

Developer 2: “Look at the “checkstyle-result.xml” file under the target subdirectory of your project to see what it’s complaining about.  There are a few things the maven version is catching that the eclipse version is not.  (So far it has always been legitimate problems).”

, ,

2 Comments