Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7035397

char[] java.io.Console.readPassword() returns null object

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 6u24
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      Microsoft Windows XP [Version 5.1.2600]
      (C) Copyright 1985-2001 Microsoft Corp.

      C:\Documents and Settings\Jon>ver

      Microsoft Windows XP [Version 5.1.2600]

      C:\Documents and Settings\Jon>java -version
      java version "1.6.0_24"
      Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
      Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)

      C:\Documents and Settings\Jon>

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]
      (C) Copyright 1985-2001 Microsoft Corp.

      C:\Documents and Settings\Jon>ver

      Microsoft Windows XP [Version 5.1.2600]

      C:\Documents and Settings\Jon>

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Eclipse IDE 3.6.2

      A DESCRIPTION OF THE PROBLEM :
      The code snippet below breaks (see error message).



      ACTUAL -
      Exception in thread "main" java.lang.NullPointerException
      at TestThree.main(TestThree.java:19)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      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 nigger?");
      String name = in.nextLine();
      String firstName = in.next();

      System.out.print("How old are you nigger?");
      int age = in.nextInt();

      System.out.print("Hello, " + name + ", next year you will be " + (age + 1) + " years old.");

      Console cons = System.console();
      char[] passwd = cons.readPassword("Password :");
      String password = null;
      for (char eachCharacter : passwd)
      {
      StringBuilder builder = new StringBuilder();
      builder.append(eachCharacter);
      password = builder.toString();
      }

      System.out.println("Password keyed in: " + password);
      }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use in.nextLine() to read the password.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: