Mladen Ivanov Kralev created FELIX-6216:
-------------------------------------------

             Summary: Refreshing bundle that logs Cyrillic text will produce 
unreadable text
                 Key: FELIX-6216
                 URL: https://issues.apache.org/jira/browse/FELIX-6216
             Project: Felix
          Issue Type: Bug
          Components: Gogo Runtime
    Affects Versions: gogo.runtime-1.1.0
            Reporter: Mladen Ivanov Kralev


*Prerequisites*

I have the following setup 
 * 0 ACTIVE org.eclipse.osgi_3.13.300.v20190218-1622
 * 1 ACTIVE org.eclipse.equinox.simpleconfigurator_1.3.200.v20181101-1115
 * 2 ACTIVE org.example.greeter_1.0.0.0000-0001
 * 3 ACTIVE org.example.greeter.en_1.0.0.0000-0001
 * 4 ACTIVE org.example.greeter.fr_1.0.0.0000-0001
 * 5 ACTIVE org.example.greeter.bg_1.0.0.0000-0001
 * 6 ACTIVE org.apache.felix.gogo.shell_1.1.0.v20180713-1646
 * 7 ACTIVE org.apache.felix.gogo.runtime_1.1.0.v20180713-1646
 * 8 ACTIVE org.apache.felix.gogo.command_1.0.2.v20170914-1324
 * 9 ACTIVE org.eclipse.equinox.console_1.3.200.v20181115-0906

The idea here is that org.example.greeter_1.0.0.0000-0001 bundle will take 
messages from:
 * 3 ACTIVE org.example.greeter.en_1.0.0.0000-0001
 * 4 ACTIVE org.example.greeter.fr_1.0.0.0000-0001
 * 5 ACTIVE org.example.greeter.bg_1.0.0.0000-0001

and log them.

The message from ACTIVE org.example.greeter.bg_1.0.0.0000-0001 is "Здравей OSGi 
world"

What I observed is that when starting this configuration of bundles: we have 
messages like:

bg: Здравей OSGi world
en: Hello OSGi world
fr: Bonjour OSGi world

If we stop the bundle 2 and then start it again we will see a log like:
bg: ╟фЁртхщ OSGi world
en: Hello OSGi world
fr: Bonjour OSGi world

I did a little debugging. I don't know the whole architecture, but... 

1. In first initialization of 
org.apache.felix.gogo.runtime.threadio.ThreadIOImpl one for first logging.
final Marker defaultMarker = new Marker(System.in, System.out, System.err, 
null);
final ThreadPrintStream *out *= new ThreadPrintStream(this, System.out, false);

Both of these will produce streams using different encodings

The reasoning behind is that:
1.java.lang.System.java will be used in defaultMarker and the default encoding 
issetOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding"))); -> 
on my machine the default is -> cp866
2.ThreadPrintStream will internally call PrintStream which calls 
OutputStreamWriter(OutputStream out) which calls se = 
StreamEncoder.forOutputStreamWriter(out, this, (String)null); which sets the 
deafult streams encoding to "file.encoding" -> on my machine -> "Cp1251"

Execution flow:
1. Default Marker will have IBM866 encoding. This will be used when greeter is 
internally printing. The logic is per thread. Lets called it Thread1
2. After Felix runtime bundle initialization, one of the input commands sets 
new encoding, (pipe-gosh --login --noshutdown) is setting new encoding
setting new Marker() which have "file.encoding" -> "Cp1251". This will be used 
Thread2
3. Stop the greeter bundle. This leads to deactivating the current Maker for 
Thread1 and setting current Marker as the previous Maker
4. Start the greeter bundle. This leads to check if the current Marker is 
activated? Find the latest enabled Maker which gets Marker from point (2) which
has different file encoding.
Note that the chain of the Makers is (1)Default Maker(IBM866) -> 
(2)Marker(Cp1251)(Latest)

5 This leads to unreadable results in the console.

As a solution, I did set both of the encodings to the same encoding. Ths leads 
to 

final Marker defaultMarker = new Marker(System.in, System.out, System.err, 
null);
final ThreadPrintStream out = new ThreadPrintStream(this, System.out, false);

to have the same encoding, therefore, stopping and starting the bundle will use 
markers with the same encoding

 

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to