ServletInputStream.readLine has several problems
- Dominant language
- Java
- Stars
- 325
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Description
The design and implementation of SerlvetInputStream.readLine has some design and implementation problems.
Firstly it is a strange method to have on a byte input stream, as a "line" may have no meaning or different meanings depending on content type. Many content types will not have the concept of a line, so this method will just strangely search for a \n byte. Other content types such as EBCDIC or UCS-2 may have different meanings of a \n byte, which still having the concept of a line.
Also, even with ASCII, UTF-8 text, lines may be terminated by \r, \r\n or just \n. Currently the implementation of this method will ignore \r and will return the \r in a \r\n sequence as part of the line.
The implementation is also not very efficient as it reads a single byte at a time.
Considering that this functionality is safely provided by BufferedReader, I believe that we should deprecate readLine - but also improve it's specification and implementation to:
+ throw illegalState exception if the content encoding is not a known to contain CR, LF characters
+ correctly handle CRLF, CR or LF
#### Environment
servlet 3.0
Contributor guide
Assessment
This issue has not been assessed yet.