This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 190817

Summary: String / byte[] problems in debugger
Product: debugger Reporter: eseerd
Component: JavaAssignee: issues@debugger <issues>
Status: RESOLVED INVALID    
Severity: normal Keywords: REGRESSION
Priority: P1    
Version: 6.x   
Hardware: PC   
OS: Windows 7   
Issue Type: DEFECT Exception Reporter:

Description eseerd 2010-10-06 21:23:52 UTC
byte[] b1 = new byte[3];
b1[0]     = 87;
b1[1]     = -2;
b1[2]     = 74;
String s = new String(b1);
byte[] b2 = s.getBytes();
for (int i = 0; i < 3 ; i++)
  System.out.println("b1 = " + b1[i] + "\tb2 = " + b2[i] );

If I run this code outside of Netbeans using jre6 u20 it prints:

b1 = 87      b2 = 87
b1 = -2      b2 = -2
b1 = 74      b2 = 74

If I run this code in Netbeans 6.5 (u20) in debug mode it prints:

b1 = 87      b2 = 87
b1 = -2      b2 = -2
b1 = 74      b2 = 74

If I run this code in Netbeans 6.9 or 6.9.1 (u20) in debug mode it prints:

b1 = 87      b2 = 87
b1 = -2      b2 = -17
b1 = 74      b2 = -65
Comment 1 Martin Entlicher 2010-10-07 06:41:14 UTC
Reproduced, but it's not a debugger problem at all. Debugger does not change the program behavior (unless the program is paused).
I've reproduced this also by running this program without debugger.

But the problem is not in NetBeans. The byte conversion is performed based on the current character encoding. If you change the encoding, the conversion can differ.

NetBeans 6.9 uses "UTF-8" encoding by default. You can change this in the project's properties (select Sources category, Encoding combo-box is on the bottom).
When you change the encoding of your project to "ISO-8859-1", the program prints the desired results:
b1 = 87        b2 = 87
b1 = -2        b2 = -2
b1 = 74        b2 = 74