Bug 151905 - Text file encoding which adds characters during decode leads to compiler error
Summary: Text file encoding which adds characters during decode leads to compiler error
Status: VERIFIED DUPLICATE of bug 149028
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 3.2.1   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-26 15:32 EDT by kantokusan CLA
Modified: 2008-09-16 10:19 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kantokusan CLA 2006-07-26 15:32:27 EDT
When using a text file encoding, which increases the byte length of Java input file, compiler reports errors like 'Syntax error, insert "}" to complete ClassBody', but the file in editor looks good and is syntactically and semantically correct.

Reproducing the error:
Encoding example which causes this error you can find at http://www.vortoj.com/sjpp/readme.html
This is a preprocessor which 'abuses' the encodimg mechanism of Java to provide a transparent preprocessing of #ifdef/#ifndef directives in a Java file by adding a special line comment, e.g. //!!! to preprocessor directives and removed source code during the decoding of Java file and removing these comment lines during encoding of file.

Analysis:
Problem is caused in file org/eclipse/jdt/internal/core/util/Util.java line 1061 by calling method 
org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(InputStream stream, int length, String encoding) with parameter length is length of file to read. 
If method getInputStreamAsCharArray is called with length value != -1 it returns a buffer of the given length independent of the data size after encoding. If encoding adds bytes, the end of file does not fit into the buffer and is skipped. This leads to compiler errors since file is read incomplete.
If line 1061 is changed to
			return org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(stream, -1, encoding);
everything works fine. Old version of this file in eclipse version 3.1.1 was implemented that way.

Conclusion:
I think this is a bug, since it is not possible to limit the length of data to read, when an encoding might increase length of read data compared to length of file. Perhaps it is neccessary to check other parts of the eclipse sources for similar problems. 
If you have any questions please send me a mail.
Comment 1 John Arthorne CLA 2008-02-27 16:47:40 EST
This bug was mis-filed and never redirected to the correct component.
Comment 2 Jerome Lanneluc CLA 2008-02-28 04:55:26 EST

*** This bug has been marked as a duplicate of bug 149028 ***
Comment 3 Frederic Fusier CLA 2008-09-16 10:19:04 EDT
Verified during 3.5M2 milestone verification process...