BUG: JLCA incorrectly matches the automatic variable of type Byte (819601)



The information in this article applies to:

  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual J++ 6.0

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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Visual J++ 6.0.
  2. On the File menu, click New Project.
  3. Expand Visual J++ Projects, click Applications, and then click Console Application in the right pane.
  4. Name the project MyVJTestApplication, and then click Open.
  5. 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());
    		}
    	}
    }
  6. On the File menu, click Save All.
  7. Quit Visual J++.
  8. Start Microsoft Visual Studio .NET 2003.
  9. On the File menu, point to Open, and then click Convert.
  10. In Available Converters, click Java Language Conversion Assistant, and then click OK.
  11. Follow the instructions in the JLCA Wizard to convert the Visual J++ project that you created in steps 2 through 6.
  12. 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="jlca1043"'
    			System.Console.Out.WriteLine(excep.ToString());
    		}
    	}

REFERENCES

For more information about the Java Language Conversion Assistant (JLCA) tool, visit the following Microsoft Web site:

Modification Type:MinorLast Reviewed:1/13/2006
Keywords:kbpending kbJava kbconvert kbbug KB819601 kbAudDeveloper