Bug 194522 - GCJ: IllegalStateException when using PrintWriter with Character Encoding
GCJ: IllegalStateException when using PrintWriter with Character Encoding
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Tom Tromey
Depends On:
Blocks: 195615
  Show dependency treegraph
Reported: 2006-06-08 14:18 EDT by IBM Bug Proxy
Modified: 2014-08-11 01:46 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-08-09 01:39:26 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description IBM Bug Proxy 2006-06-08 14:18:40 EDT
LTC Owner is: gjlynx@us.ibm.com
LTC Originator is: TAPHORN@de.ibm.com

Problem description:
We wanted to use the java.io.PrintWriter with an encoding different from the
systems default encodig. The compile is working properly, but when the execution
reaches the execution of the PrintWriter.println(String) method it executes with
an IllegalStateException.
When using the SystemsDefault Encoding (we use here the following consturctor:
PrintWriter(OutputStreamWriter)) everything works fine. But when we specify the
encoder directly (we then use the constructor: PrintWriter(OutputStreamWriter,
CharsetEncoder)) like UTF-8 or ISO-8859-1, the IllegalStateException it thrown.
The problem seems to be located in the GCJ internal implementation when not
using the default encoder in the PrintWriter.

The used Fedora Core 5 system is a native FC5 installation with latest upgrades
from 'core', 'updates' and 'extras' repositories.

uname -a displays: 
  Linux <hostname> 2.6.16-1.2122_FC5 #1 Sun May 21 15:01:01 EDT 2006 i686 i686
i386 GNU/Linux
java -version:
  java version "1.4.2"
  gij (GNU libgcj) version 4.1.1 20060525 (Red Hat 4.1.1-1)

Hardware Environment
    Machine type (p650, x235, SF2, etc.): 2668 (T43p ThinkPad)
    Cpu type (Power4, Power5, IA-64, etc.): I686

The problem was found by Michael Bauschert <michael.bauschert@de.ibm.com>. For
further information, please contact him (on vacation from 06/12 until 06/26).

Due to the fact that this is just an application problem, it is reproducable on
any other machine.

Is this reproducible?
  If so, how long does it (did it) take to reproduce it?
  Just compile the following Java Sources added at the bottom of this bugzilla
and process the steps described below.

  Describe the steps:
  - Compile the previous sources with the gcj compiler with the following command:
    gcj -C TestPrintWriter.java
  - Verify that the gcj is the systems JVM
  - Create a file for example with 'echo hello > test4printwriter.in'.
  - Process the test first by using the systems default encoding:
    java -cp . TestPrintWriter test4printwriter.in none
  - Process the test a second time by using a different encodign:
    java -cp . TestPrintWriter test4printwriter.in ISO-8859-1

Is the system (not just the application) hung?
    No, this is just an application runtime problem.

Did the system produce an OOPS message on the console?

Is the system sitting in a debugger right now?

Additional information:
    The problem appeared only while using the GCJ. The problem was not
recognized when using the IBM or SUN JVM.

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;

public class TestPrintWriter {
        private static final String ENV_OUT = "env.out";
        private static final int IDX_ENCODING = 1;
        private static final int IDX_FILE = 0;
        private static final String DEFAULT_ENCODING = "file.encoding: " +
System.getProperty("file.encoding") + " - file.encoding.pkg: " +

         * @param args
         * @throws Exception
        public static void main(String[] args)
                try {
                        if (args.length != 2)

                        Properties props = System.getProperties();
                        Enumeration e = props.keys();
                        List list = new java.util.ArrayList();

                        while (e.hasMoreElements())
                                String key = (String)e.nextElement();

                        Collections.sort(list,new java.util.Comparator(){
                                        public int compare(Object o1, Object o2)
                                                String s1 = (String)o1;
                                                String s2 = (String)o2;
                                                return s1.compareTo(s2);
                        java.util.Iterator it = list.iterator();
                        PrintWriter pw = new PrintWriter(new
                        while (it.hasNext())
                                String key = (String)it.next();
                                String value = System.getProperty(key);
                                pw.println(key + " = " + value);
                        System.out.println("Writing environment to " +

                        System.out.println("Input is " +

                        BufferedReader in = new BufferedReader(new
                                System.out.println("Using Default-Encoding " +
                                pw = new PrintWriter(new
                                System.out.println("Using Encoding " +
                                Charset charset =
                                pw = new PrintWriter(new

                        String line = null;
                        while ((line = in.readLine()) != null)
                } catch (Exception e) {

        private static void printUsage() {
                System.err.println("Usage: java TestPrintWriter file encoding
\n\nfile must be absolute or relative to working dir\nencoding = US-ASCII,
ISO-8859-1... - use 'none' for using the platforms default encoding " +

Comment 1 Tom Tromey 2006-06-23 14:14:26 EDT
FWIW I'm seeing this with gcj svn trunk as well.
Comment 2 Tom Tromey 2006-06-27 16:27:59 EDT
I've checked in a patch for this to gcc svn trunk.
Comment 3 IBM Bug Proxy 2006-07-13 04:00:58 EDT
----- Additional Comments From TAPHORN@de.ibm.com  2006-07-13 04:02 EDT -------
Thanks for the update.

Since I'm new to all of the processes with bug reporting, verifying ...
Is there any outlook when the patch will be integrated into a package for FC5
and/or FC6 (FC Devel)? This would make life much easier for me to verify that
the problem is fixed. 
Comment 4 Anthony Green 2006-08-04 11:34:27 EDT
(In reply to comment #3)
> Since I'm new to all of the processes with bug reporting, verifying ...
> Is there any outlook when the patch will be integrated into a package for FC5
> and/or FC6 (FC Devel)? This would make life much easier for me to verify that
> the problem is fixed. 

I believe this has been integrated into FC6.  I've tested it there and it worked.
I don't know about FC5.  tromey?
Comment 5 Tom Tromey 2006-08-08 20:01:02 EDT
This patch should already be in FC6 test 2.
It was definitely in the big libgcj backport...

I don't think this can go in FC5, as it breaks ABI.
When writing it I didn't see an easy way to make a non-breaking
patch; that's why it didn't go in the GCC 4.1 branch.

Is FC6 sufficient?
If not I could take another look.  But, I'd prefer not to if possible.
Comment 6 IBM Bug Proxy 2006-08-30 12:01:05 EDT
----- Additional Comments From TAPHORN@de.ibm.com  2006-08-30 11:58 EDT -------
Well,  think FC6 is good enough for us.
Hopefully the fix will also be included into the next RHEL distro.

btw: I checked the problem against the latest GCJ on FC6 and it worked properly,
as expected. 

Note You need to log in before you can comment on or make changes to this bug.