Buggy code:
public final class Main { private static final Logger LOG = LoggerFactory . getLogger ( Main . class ) ; private static final String PROGRAM = "redpen-cli" ; private static final String VERSION = "1.1" ; private static final int EDEFAULT_LIMIT = 1 ; private Main ( ) { } public static void main ( String ... args ) throws RedPenException { } public static int run ( String ... args ) { Options options = new Options ( ) ; options . addOption ( "h" , "help" , false , "Displays<seq2seq4repair_space>this<seq2seq4repair_space>help<seq2seq4repair_space>information<seq2seq4repair_space>and<seq2seq4repair_space>exits" ) ; OptionBuilder . withLongOpt ( "format" ) ; OptionBuilder . withDescription ( "Input<seq2seq4repair_space>file<seq2seq4repair_space>format" ) ; OptionBuilder . hasArg ( ) ; OptionBuilder . withArgName ( "FORMAT" ) ; options . addOption ( OptionBuilder . create ( "f" ) ) ; OptionBuilder . withLongOpt ( "conf" ) ; OptionBuilder . withDescription ( "Configuration<seq2seq4repair_space>file<seq2seq4repair_space>(REQUIRED)" ) ; OptionBuilder . hasArg ( ) ; OptionBuilder . withArgName ( "CONF<seq2seq4repair_space>FILE" ) ; options . addOption ( OptionBuilder . create ( "c" ) ) ; OptionBuilder . withLongOpt ( "result-format" ) ; OptionBuilder . withDescription ( "Output<seq2seq4repair_space>result<seq2seq4repair_space>format" ) ; OptionBuilder . hasArg ( ) ; OptionBuilder . withArgName ( "RESULT<seq2seq4repair_space>FORMAT" ) ; options . addOption ( OptionBuilder . create ( "r" ) ) ; OptionBuilder . withLongOpt ( "limit" ) ; OptionBuilder . withDescription ( "error<seq2seq4repair_space>limit<seq2seq4repair_space>number" ) ; OptionBuilder . hasArg ( ) ; OptionBuilder . withArgName ( "LIMIT<seq2seq4repair_space>NUMBER" ) ; options . addOption ( OptionBuilder . create ( "l" ) ) ; options . addOption ( "v" , "version" , false , "Displays<seq2seq4repair_space>version<seq2seq4repair_space>information<seq2seq4repair_space>and<seq2seq4repair_space>exits" ) ; CommandLineParser commandLineParser = new BasicParser ( ) ; CommandLine commandLine ; try { commandLine = commandLineParser . parse ( options , args ) ; } catch ( ParseException e ) { Main . LOG . error ( "Error<seq2seq4repair_space>occurred<seq2seq4repair_space>in<seq2seq4repair_space>parsing<seq2seq4repair_space>command<seq2seq4repair_space>line<seq2seq4repair_space>options<seq2seq4repair_space>" ) ; Main . printHelp ( options ) ; return - 1 ; } String inputFormat = "plain" ; String configFileName = "" ; String resultFormat = "plain" ; int limit = Main . EDEFAULT_LIMIT ; if ( commandLine . hasOption ( "h" ) ) { Main . printHelp ( options ) ; return 0 ; } if ( commandLine . hasOption ( "v" ) ) { System . out . println ( Main . VERSION ) ; return 0 ; } if ( commandLine . hasOption ( "f" ) ) { inputFormat = commandLine . getOptionValue ( "f" ) ; } if ( commandLine . hasOption ( "c" ) ) { configFileName = commandLine . getOptionValue ( "c" ) ; } if ( commandLine . hasOption ( "r" ) ) { resultFormat = commandLine . getOptionValue ( "r" ) ; } if ( commandLine . hasOption ( "l" ) ) { limit = Integer . valueOf ( commandLine . getOptionValue ( "l" ) ) ; } String [ ] inputFileNames = commandLine . getArgs ( ) ; File [ ] inputFiles = new File [ inputFileNames . length ] ; for ( int i = 0 ; i < ( inputFileNames . length ) ; i ++ ) { inputFiles [ i ] = new File ( inputFileNames [ i ] ) ; } DocumentParser parser = DocumentParser . of ( inputFormat ) ; Formatter formatter ; switch ( resultFormat . toLowerCase ( ) ) { case "xml" : formatter = new XMLFormatter ( ) ; break ; case "plain" : formatter = new PlainFormatter ( ) ; break ; case "json" : formatter = new JSONFormatter ( ) ; break ; default : Main . LOG . error ( ( "Unsupported<seq2seq4repair_space>format:" + resultFormat ) ) ; return - 1 ; } if ( ( configFileName == null ) || ( ( configFileName . length ( ) ) == 0 ) ) { Main . LOG . error ( "Configuration<seq2seq4repair_space>file<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>specified." ) ; Main . printHelp ( options ) ; return 1 ; } else if ( ( inputFileNames . length ) == 0 ) { Main . LOG . error ( "Input<seq2seq4repair_space>file<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>given" ) ; Main . printHelp ( options ) ; return 1 ; } RedPen redPen ; List < Document > documents ; try { redPen = new RedPen ( new File ( configFileName ) ) ; documents = redPen . parse ( parser , inputFiles ) ; } catch ( RedPenException e ) { Main . LOG . error ( ( "Failed<seq2seq4repair_space>to<seq2seq4repair_space>parse<seq2seq4repair_space>input<seq2seq4repair_space>files:<seq2seq4repair_space>" + e ) ) ; return - 1 ; } if ( documents == null ) { Main . LOG . error ( "Failed<seq2seq4repair_space>to<seq2seq4repair_space>create<seq2seq4repair_space>a<seq2seq4repair_space>DocumentCollection<seq2seq4repair_space>object" ) ; return - 1 ; } Map < Document , List < ValidationError > > documentListMap = redPen . validate ( documents ) ; String result = formatter . format ( documentListMap ) ; System . out . println ( result ) ; <START_BUG> long errorCount = documentListMap . values ( ) . stream ( ) . map ( List :: size ) . count ( ) ; <END_BUG> if ( errorCount > limit ) { Main . LOG . error ( "The<seq2seq4repair_space>number<seq2seq4repair_space>of<seq2seq4repair_space>errors<seq2seq4repair_space>\"{}\"<seq2seq4repair_space>is<seq2seq4repair_space>larger<seq2seq4repair_space>than<seq2seq4repair_space>specified<seq2seq4repair_space>(limit<seq2seq4repair_space>is<seq2seq4repair_space>\"{}\")." , errorCount , limit ) ; return 1 ; } else { return 0 ; } } private static void printHelp ( Options opt ) { } }

Fix:
long errorCount = documentListMap . values ( ) . stream ( ) . mapToLong ( List :: size ) . sum ( ) ;