[ https://issues.apache.org/jira/browse/GROOVY-8546?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16440281#comment-16440281 ]
Daniel Sun commented on GROOVY-8546: ------------------------------------ {quote}It would help if you linked to the relevant source code since the groovy-all sources jar does not carry the Antlr source. {quote} Here is the source code of antlr4's {{fromReader}}: {code:java} /** * Creates a {@link CharStream} given a {@link Reader} and its * source name. Closes the reader before returning. */ public static CodePointCharStream fromReader(Reader r, String sourceName) throws IOException { try { CodePointBuffer.Builder codePointBufferBuilder = CodePointBuffer.builder(DEFAULT_BUFFER_SIZE); CharBuffer charBuffer = CharBuffer.allocate(DEFAULT_BUFFER_SIZE); while ((r.read(charBuffer)) != -1) { charBuffer.flip(); codePointBufferBuilder.append(charBuffer); charBuffer.compact(); } return CodePointCharStream.fromBuffer(codePointBufferBuilder.build(), sourceName); } finally { r.close(); } } {code} I verified that *only the reader created by `getReader` method in {{Antlr4ParserPlugin}} is not closed*, here is the commit to fix it: https://github.com/apache/groovy/commit/e19a93242dcc204cd94e034242a348c113cc1130 As for other Reader/Stream instances, they have been closed, you have to investigate the relevant code to check. > Parrot Parser: multiple Reader instances opened from SourceUnit; many left > open > ------------------------------------------------------------------------------- > > Key: GROOVY-8546 > URL: https://issues.apache.org/jira/browse/GROOVY-8546 > Project: Groovy > Issue Type: Bug > Components: parser > Affects Versions: 2.6.0-alpha-3, 3.0.0-alpha-2 > Reporter: Eric Milles > Priority: Major > > {{Antlr4ParserPlugin}} makes very inefficient use of > {{ReaderSource}}/{{SourceUnit}}. {{parseCST}} is passed a {{Reader}} with > the idea that it is the source of character data -- and this reader is closed > from outside. It ignores this and mines the passed {{SourceUnit}}, which > seems unnecessary since the same reference is passed again in {{buildAST}}. > Both {{parseCST}} and {{buildAST}} call {{getReader}}, which opens a buffered > reader on the source unit file and never closes them. Lastly, {{AstBuilder}} > calls {{getReader}} as well to create a {{CharStream}} and never closes this > reader. > Doing this in a long-running process (like an IDE) is causing numerous > problems due to open file handles. > {code:java} > public class Antlr4ParserPlugin implements ParserPlugin { > private ReaderSource readerSource; > @Override > public Reduction parseCST(SourceUnit sourceUnit, java.io.Reader reader) > throws CompilationFailedException { > try { > ReaderSource readerSource = sourceUnit.getSource(); > if (null != readerSource && null != readerSource.getReader()) { > this.readerSource = readerSource; > } else { > this.readerSource = new > StringReaderSource(IOGroovyMethods.getText(reader), > sourceUnit.getConfiguration()); > } > } catch (IOException e) { > throw new GroovyBugError("Failed to create StringReaderSource > instance", e); > } > return null; > } > @Override > public ModuleNode buildAST(SourceUnit sourceUnit, ClassLoader > classLoader, Reduction cst) throws ParserException { > try { > ReaderSource readerSource = sourceUnit.getSource(); > if (null == readerSource || null == readerSource.getReader()) { > sourceUnit.setSource(this.readerSource); > } > } catch (IOException e) { > sourceUnit.setSource(this.readerSource); > } > AstBuilder builder = new AstBuilder(sourceUnit); > return builder.buildAST(); > } > } > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)