From c6076730de3b7b587ca0e1d6e31f5e7bd6ab6761 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 19 Mar 2021 05:07:15 +0100 Subject: [ecj] [bug-workarounds] The last comment in a line is lost if the array handed to the scanner is exactly sized to the input to process. --- .../javac/java8/CommentCollectingScannerFactory.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java') diff --git a/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java b/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java index 767cbf5b..f29f501b 100644 --- a/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java +++ b/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java @@ -75,8 +75,24 @@ public class CommentCollectingScannerFactory extends ScannerFactory { @SuppressWarnings("all") @Override public Scanner newScanner(CharSequence input, boolean keepDocComments) { - char[] array = input.toString().toCharArray(); - return newScanner(array, array.length, keepDocComments); + char[] array; + int limit; + if (input instanceof CharBuffer && ((CharBuffer) input).hasArray()) { + CharBuffer cb = (CharBuffer) input; + cb.compact().flip(); + array = cb.array(); + limit = cb.limit(); + } else { + array = input.toString().toCharArray(); + limit = array.length; + } + if (array.length == limit) { + // work around a bug where the last comment in a file falls away in this case. + char[] d = new char[limit + 1]; + System.arraycopy(array, 0, d, 0, limit); + array = d; + } + return newScanner(array, limit, keepDocComments); } @Override -- cgit