-
Bug
-
Resolution: Fixed
-
P4
-
5.0, 5.0u3
-
b78
-
generic, x86
-
generic, windows_xp
Bug Description: OS VERSION: Windows XP Professional
JDK VERSION :
java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b05)
Java HotSpot(TM) Client VM (build 1.5.0_03-b05, mixed mode)
PROBLEM DESCRIPTION:
If a Formatter object is created with a null Appendable, then the destination
for the formmater should be a StringBuilder. Hence, calling the out() method
with this Formatter object should return a StringBuilder.
But here in this case, calling the out() method with this Formatter object
results in throwing java.util.FormatterClosedException.
When we create a Formatter object with a null Appendable using the constructor
public Formatter(Appendable a),
the out() method of this Formatter object should return a destination which
should be a StringBuilder. But in this case it throws java.util.FormatterClosedException,
which is not the expected behaviour.
This is present in the FormatterTestError.java file.
FURTHER INFORMATION:
But when we create a Formatter object with a null Appendable and null Locale using
the constructor
public Formatter(Appendable a,Locale l),
the out() method of this constructor returns an instance of StringBuilder only and this
is the expected behaviour.
This is present in the FormatterTest.java file.
STEPS TO REPRODUCE:
1) Compile the java file FormatterTestError.java
javac FormatterTestError.java
2) Run the java file
java FormatterTestError
3) You can see java.util.FormatterClosedException thrown on the command prompt:
C:\transfer\Eclipse\eclipse-2.1\workspace>C:\downloads\jdk1.5.0_03\bin\java FormatterTestError
java.util.FormatterClosedException
at java.util.Formatter.ensureOpen(Formatter.java:2315)
at java.util.Formatter.out(Formatter.java:2226)
at FormatterTestError.main(FormatterTestError.java:13)
4) Compile the java file FormatterTest.java
javac FormatterTest.java
5) Run the java file
java FormatterTest
6) You can see it doesn't throw any exception.
###@###.### 2005-03-14 16:00:57 GMT
3/24/05 test cases from IBM
import java.util.*;
public class FormatterTest
{
public static void main(String args[])
{
try
{
Appendable a=null;
Locale locale=null;
Formatter formatterAppendableLocale=new Formatter(a,locale);
if ( (formatterAppendableLocale.out()) instanceof StringBuilder
)
System.out.println("TEST PASSED");
else
System.out.println("TEST FAILED");
} catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException("TEST FAILED");
}
}
}
====
import java.util.*;
public class FormatterTestError
{
public static void main(String args[])
{
Appendable a=null;
Formatter formatter=new Formatter(a);
try
{
if ( (formatter.out()) instanceof StringBuilder )
System.out.println("TEST PASSED");
else
System.out.println("TEST FAILED");
} catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException("TEST FAILED");
}
}
}
###@###.### 2005-03-24 23:25:04 GMT
JDK VERSION :
java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b05)
Java HotSpot(TM) Client VM (build 1.5.0_03-b05, mixed mode)
PROBLEM DESCRIPTION:
If a Formatter object is created with a null Appendable, then the destination
for the formmater should be a StringBuilder. Hence, calling the out() method
with this Formatter object should return a StringBuilder.
But here in this case, calling the out() method with this Formatter object
results in throwing java.util.FormatterClosedException.
When we create a Formatter object with a null Appendable using the constructor
public Formatter(Appendable a),
the out() method of this Formatter object should return a destination which
should be a StringBuilder. But in this case it throws java.util.FormatterClosedException,
which is not the expected behaviour.
This is present in the FormatterTestError.java file.
FURTHER INFORMATION:
But when we create a Formatter object with a null Appendable and null Locale using
the constructor
public Formatter(Appendable a,Locale l),
the out() method of this constructor returns an instance of StringBuilder only and this
is the expected behaviour.
This is present in the FormatterTest.java file.
STEPS TO REPRODUCE:
1) Compile the java file FormatterTestError.java
javac FormatterTestError.java
2) Run the java file
java FormatterTestError
3) You can see java.util.FormatterClosedException thrown on the command prompt:
C:\transfer\Eclipse\eclipse-2.1\workspace>C:\downloads\jdk1.5.0_03\bin\java FormatterTestError
java.util.FormatterClosedException
at java.util.Formatter.ensureOpen(Formatter.java:2315)
at java.util.Formatter.out(Formatter.java:2226)
at FormatterTestError.main(FormatterTestError.java:13)
4) Compile the java file FormatterTest.java
javac FormatterTest.java
5) Run the java file
java FormatterTest
6) You can see it doesn't throw any exception.
###@###.### 2005-03-14 16:00:57 GMT
3/24/05 test cases from IBM
import java.util.*;
public class FormatterTest
{
public static void main(String args[])
{
try
{
Appendable a=null;
Locale locale=null;
Formatter formatterAppendableLocale=new Formatter(a,locale);
if ( (formatterAppendableLocale.out()) instanceof StringBuilder
)
System.out.println("TEST PASSED");
else
System.out.println("TEST FAILED");
} catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException("TEST FAILED");
}
}
}
====
import java.util.*;
public class FormatterTestError
{
public static void main(String args[])
{
Appendable a=null;
Formatter formatter=new Formatter(a);
try
{
if ( (formatter.out()) instanceof StringBuilder )
System.out.println("TEST PASSED");
else
System.out.println("TEST FAILED");
} catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException("TEST FAILED");
}
}
}
###@###.### 2005-03-24 23:25:04 GMT