Microsoft KB Archive/819601

= BUG: JLCA incorrectly matches the automatic variable of type Byte =

Article ID: 819601

Article Last Modified on 5/16/2007

-

APPLIES TO


 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual J++ 6.0 Standard Edition

-



SYMPTOMS
You have a Microsoft Visual J++ project that contains a variable of type byte as an argument for a method. When you use the Java Language Conversion Assistant (JLCA) tool to convert you Visual J++ project to Microsoft Visual C# .NET, JLCA converts variables of type byte to type sbyte (signed byte).

When Automatic variables of type byte are assigned to other variables of type byte, JLCA converts the assignment in Visual C# .NET as follows:
 * 1) JLCA uses the ToSByteArray method of SupportClass to convert Automatic variables of type byte to type sbyte.
 * 2) JLCA uses the ToByteArray method of SupportClass to convert variables of type sbyte to variables of type byte.

Note JLCA creates the SupportClass class. This class is available in the converted Visual C# .NET project.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 Start Visual J++ 6.0. On the File menu, click New Project. Expand Visual J++ Projects, click Applications, and then click Console Application in the right pane. Name the project MyVJTestApplication, and then click Open.  Replace the existing code with the following sample code: import java.io.*;

public class Class1 {   OutputStream outStream = null;

Class1(OutputStream outStream) {       this.outStream = outStream; }   public void WriteTheTextOnConsole(byte[] buffer, int offset, int length) throws IOException {       try {           String s = new String(buffer, offset, length); StringBuffer sb = new StringBuffer(s); buffer = sb.toString.getBytes; outStream.write(buffer, 0, buffer.length); }       catch (Exception excep) {           System.out.println(excep.toString); }   }

public static void main(String[] args) {       try {           Class1 myObj = new Class1(System.out); byte[] myBuffer = new byte[20]; myObj.WriteTheTextOnConsole(myBuffer, 0, 20); }       catch (Exception excep) {           System.out.println(excep.toString); }   } }  On the File menu, click Save All. Quit Visual J++.</li> Start Microsoft Visual Studio .NET 2003.</li> On the File menu, point to Open, and then click Convert.</li> In Available Converters, click Java Language Conversion Assistant, and then click OK.</li> Follow the instructions in the JLCA Wizard to convert the Visual J++ project that you created in steps 2 through 6.</li>  In the WriteTheTextOnConsole method of the Visual C# .NET code that the converter generates, notice that byte is casted to sbyte, and then converted to byte by using the ToByteArray method of SupportClass. The code that the converter generates for the WriteTheTextOnConsole method appears as follows: public virtual void WriteTheTextOnConsole(sbyte[] buffer, int offset, int length) {       try {           char[] tmpChar; tmpChar = new char[buffer.Length]; buffer.CopyTo(tmpChar, 0); System.String s = new System.String(tmpChar, offset, length); System.Text.StringBuilder sb = new System.Text.StringBuilder(s); buffer = SupportClass.ToSByteArray(SupportClass.ToByteArray(sb.ToString)); outStream.Write(SupportClass.ToByteArray(buffer), 0, buffer.Length); }       catch (System.Exception excep) {           //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' //may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword=&quot;jlca1043&quot;' System.Console.Out.WriteLine(excep.ToString); }   } </li></ol>

<div class="references_section">