| Summary: | Null pointer exception upon reading char[] value | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Jonathan Camilleri <camilleri.jon> | ||||
| Component: | Debug | Assignee: | JDT-Debug-Inbox <jdt-debug-inbox> | ||||
| Status: | CLOSED DUPLICATE | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | daniel_megert | ||||
| Version: | 3.7 | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows XP | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
Created attachment 192904 [details]
Code snippet
*** This bug has been marked as a duplicate of bug 122429 *** |
Build Identifier: M20110210-1200 When I run this code: import java.util.*; import java.io.*; import java.lang.*; public class TestThree { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print ("What's your name?"); String name = in.nextLine(); //String firstName = in.next(); System.out.print("How old are you?"); int age = in.nextInt(); System.out.println("Hello, " + name + ", next year you will be " + (age + 1) + " years old."); Console cons = System.console(); System.out.println("Enter a password:"); char[] charPasswd = cons.readPassword("[%s]", "Password :"); String strPassword = null; StringBuilder builder = new StringBuilder(); builder.append(charPasswd); strPassword = builder.toString(); System.out.println("Password keyed in: " + strPassword); } } I get this output: What's your name?Jon C. How old are you?31 Hello, Jon C., next year you will be 32 years old.Exception in thread "main" java.lang.NullPointerException at TestThree.main(TestThree.java:21) Enter a password: The code snippet works as expected when compiling through the command line (javac.exe) Reproducible: Always