Empty Line Separator Check, fixed Exception if file doesn't have header, issue #621
This commit is contained in:
parent
351d79582d
commit
7c262e61e6
|
|
@ -285,11 +285,15 @@ public class EmptyLineSeparatorCheck extends Check
|
|||
*/
|
||||
private boolean isPrePreviousLineEmpty(DetailAST token)
|
||||
{
|
||||
boolean result = false;
|
||||
final int lineNo = token.getLineNo();
|
||||
// 3 is the number of the pre-previous line because the numbering starts from zero.
|
||||
final int number = 3;
|
||||
final String prePreviousLine = getLines()[lineNo - number];
|
||||
return prePreviousLine.trim().isEmpty();
|
||||
if (lineNo >= number) {
|
||||
final String prePreviousLine = getLines()[lineNo - number];
|
||||
result = prePreviousLine.trim().isEmpty();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -81,4 +81,15 @@ public class EmptyLineSeparatorCheckTest
|
|||
};
|
||||
verify(checkConfig, getPath("whitespace/InputEmptyLineSeparatorCheckMultipleEmptyLines.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormerArrayIndexOutOfBounds() throws Exception
|
||||
{
|
||||
DefaultConfiguration checkConfig = createCheckConfig(EmptyLineSeparatorCheck.class);
|
||||
checkConfig.addAttribute("allowMultipleEmptyLines", "false");
|
||||
final String[] expected = {
|
||||
|
||||
};
|
||||
verify(checkConfig, getPath("whitespace/InputEmptyLineSeparatorFormerException.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package com.puppycrawl.tools.checkstyle.whitespace;
|
||||
|
||||
public class InputEmptyLineSeparatorFormerException
|
||||
{
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue