hlapidez / anhquan Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/anhquan
Automatically exported from code.google.com/p/anhquan
What steps will reproduce the problem?
1. Reader reader = new StringReader(" \n\n \n size\n 30 40 ");
2. Scanner scanner = new Scanner(reader);
3. scanner.next();
4. System.out.println(scanner.next());
What is the expected output? What do you see instead?
Should output empty string "";
Actually prints null.
This is a problem because aside from being a little counter-intuitive, the
behavior differs from the standard java.io library behavior and breaks
compatibility with scanners and such.
The source code of BufferedReader.readLine() is:
/**
* Reads the next line of characters.
*
* @return The next line.
*/
public String readLine() throws IOException {
StringBuilder sb = null;
boolean eol = false;
int nextChar = read();
while (!eol && (nextChar != -1)) {
if (nextChar == 10) {
eol = true;
} else if (nextChar == 13) {
eol = true;
// Check if there is a immediate LF following the CR
nextChar = read();
if (nextChar != 10) {
this.savedNextChar = nextChar;
}
}
if (!eol) {
if (sb == null) {
sb = new StringBuilder();
}
sb.append((char) nextChar);
nextChar = read();
}
}
return (sb == null) ? null : sb.toString();
}
I believe you can fix the problem by replacing the last return statement with:
if (sb == null) {
if(nextChar != -1){
return "";
}
return null;
}
return sb.toString();
Also, thanks for the useful lib. Some form of java.io should really be included
in gwt because it's used very frequently and makes porting things to gwt a real
pain if you don't have this library.
Original issue reported on code.google.com by [email protected]
on 4 May 2012 at 10:56
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.