gephi/gephi — Issue #488: Some text appears garbled when loaded from a project file
Author: claui
Created: 2011-12-04 16:13:57+00:00
State: open

## Issue description

Non-ASCII text content is displayed garbled when loaded from a Gephi project file.

The issue occurs since Project API 0.8.0.1. In fact, it occurred right away after I had updated the Project API plugin from 0.8.0 to 0.8.0.1.

This is reproducible on my Mac and possibly affects other, if not all, OS X systems.

Saving seems to work properly; the issue affects only loading. It does not matter if the project was saved using the last plugin version or the new one.

## Steps to reproduce

The issue is 100 % reproducible on my Mac. Just create a new project with a single node labeled

> ÄÖÜ

and save. As soon as the project is loaded again, the label says

> √Ñ√ñ√ú

My guess is that the issue affects systems whose Java runtime does NOT use UTF-8 as its default character encoding (e. g. the Java runtime on Mac OS).
So it might be reproducible on any Mac OS system, possibly even on a few other OSs.

## Possible cause

My guess is that the issue might have been introduced with the fix for issue #465.

I have looked at the changes in 8f9dfd51f354bea3582fc3a582d867d92dbc9735 for a bit. It introduces an intermediate `InputStreamReader` (see line 103) whose purpose is to filter out certain characters. It is then piped to both the original input stream and the `XMLStreamReader`.

The original file input stream is not handed directly to the XMLStreamReader anymore. Instead it’s now the InputStreamReader’s duty to decode bytes to characters – and to use the proper character encoding (XMLStreamReader did both before the change).

However, the constructor in line 103 – `InputStreamReader(java.io.InputStream)` – by specification just asks the Java runtime for the default encoding, which happens to be MacRoman on the Mac.

As far as my guesswork is correct, the actual XML should be UTF-8 … so the InputStreamReader gets incorrect info about the encoding and creates the incorrect characters which it then hands further down to the XMLStreamReader.

Perhaps this could be fixed by just using `InputStreamReader(java.io.InputStream, java.nio.charset.Charset)` instead, a version of the constructor which takes the character encoding as an argument.

## Workaround

The issue went away when I downgraded to version 0.8.0 of the Project API plugin.

## See also

Issue #474 (November 15, 2011) mentions a similar problem with GEXF files.