Bug 194522 - GCJ: IllegalStateException when using PrintWriter with Character Encoding
Summary: GCJ: IllegalStateException when using PrintWriter with Character Encoding
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: rawhide
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Tom Tromey
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: 195615
TreeView+ depends on / blocked
 
Reported: 2006-06-08 18:18 UTC by IBM Bug Proxy
Modified: 2014-08-11 05:46 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-08-09 05:39:26 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description IBM Bug Proxy 2006-06-08 18:18:40 UTC
LTC Owner is: gjlynx.com
LTC Originator is: TAPHORN.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.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?
    Nope.


Is the system sitting in a debugger right now?
    Nope.


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


-----
TestPrintWriter.java
-----
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: " +
System.getProperty("file.encoding.pkg");

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

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

                        while (e.hasMoreElements())
                        {
                                String key = (String)e.nextElement();
                                list.add(key);
                        }

                        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
FileWriter(TestPrintWriter.ENV_OUT));
                        while (it.hasNext())
                        {
                                String key = (String)it.next();
                                String value = System.getProperty(key);
                                pw.println(key + " = " + value);
                        }
                        System.out.println("Writing environment to " +
TestPrintWriter.ENV_OUT);


                        System.out.println("Input is " +
args[TestPrintWriter.IDX_FILE]);

                        BufferedReader in = new BufferedReader(new
FileReader(args[TestPrintWriter.IDX_FILE]));
                        if
(args[TestPrintWriter.IDX_ENCODING].equalsIgnoreCase("none"))
                        {
                                System.out.println("Using Default-Encoding " +
DEFAULT_ENCODING);
                                pw = new PrintWriter(new
OutputStreamWriter(System.out));
                        }
                        else
                        {
                                System.out.println("Using Encoding " +
args[TestPrintWriter.IDX_ENCODING]);
                                Charset charset =
Charset.forName(args[TestPrintWriter.IDX_ENCODING]);
                                pw = new PrintWriter(new
OutputStreamWriter(System.out,charset.newEncoder()));
                        }

                        String line = null;
                        while ((line = in.readLine()) != null)
                        {
                                pw.println(line);
                        }
                        pw.flush();
                        pw.close();
                } catch (Exception e) {
                        e.printStackTrace();
                        System.err.println();
                        printUsage();
                }
        }

        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 " +
DEFAULT_ENCODING);
        }

}
-----

Comment 1 Tom Tromey 2006-06-23 18:14:26 UTC
FWIW I'm seeing this with gcj svn trunk as well.


Comment 2 Tom Tromey 2006-06-27 20:27:59 UTC
I've checked in a patch for this to gcc svn trunk.


Comment 3 IBM Bug Proxy 2006-07-13 08:00:58 UTC
----- Additional Comments From TAPHORN.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 15:34:27 UTC
(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-09 00:01:02 UTC
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 16:01:05 UTC
----- Additional Comments From TAPHORN.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.