Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 342377 - Null pointer exception upon reading char[] value
Summary: Null pointer exception upon reading char[] value
Status: CLOSED DUPLICATE of bug 122429
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-10 14:18 EDT by Jonathan Camilleri CLA
Modified: 2011-04-11 05:52 EDT (History)
1 user (show)

See Also:


Attachments
Code snippet (1.28 KB, application/octet-stream)
2011-04-10 14:19 EDT, Jonathan Camilleri CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Camilleri CLA 2011-04-10 14:18:50 EDT
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
Comment 1 Jonathan Camilleri CLA 2011-04-10 14:19:40 EDT
Created attachment 192904 [details]
Code snippet
Comment 2 Dani Megert CLA 2011-04-11 05:52:32 EDT

*** This bug has been marked as a duplicate of bug 122429 ***