United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4887461 : NullPointerException when trying to pass byte[] between JVM and ActiveX

Details
Type:
Bug
Submit Date:
2003-07-08
Status:
Resolved
Updated Date:
2004-09-28
Project Name:
JDK
Resolved Date:
2003-08-19
Component:
deploy
OS:
generic,windows_2000
Sub-Component:
plugin
CPU:
x86,generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
1.4.2,1.4.2_05
Fixed Versions:
5.0 (tiger)

Related Reports
Backport:
Duplicate:

Sub Tasks

Description

Name: gm110360			Date: 07/08/2003


FULL PRODUCT VERSION :
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)


FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

EXTRA RELEVANT SYSTEM CONFIGURATION :
.NET Framework SP2

A DESCRIPTION OF THE PROBLEM :
Re-packaging an existing bean for the Java Plugin 1.4.2 (from 1.3.1_07) I found that I could not pass a byte[] between VB (6 or .NET) and the JVM.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a JavaBean that acts on a byte[] (I modified the ArrayBean example that
Devananda Jayaraman had provided), package it, register it.
Create a VB project (6 or .NET)
Add code to create it and call a method that accepts a byte[] (in my example, pickByte)



EXPECTED VERSUS ACTUAL BEHAVIOR :
I should have received a byte back.
Runtime error '-2147352567 (80020009)':
java.lang.NullPointerException

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Runtime error '-2147352567 (80020009)':
java.lang.NullPointerException

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Java Bean (ArrayBean2.java)
---------------------------
public class ArrayBean2 implements java.io.Serializable
{
   private int propI;
   private byte propB;
   public ArrayBean2()
   {
   }
   public int getPropI ()
   {
      return propI;
   }
   public void setPropI (int i)
   {
      propI = i;
   }
   public byte getPropB ()
   {
      return propB;
   }
   public void setPropB (byte s)
   {
      propB = s;
   }
   public byte pickByte (byte[] array, int index)
   {
     return (array[index]);
   }
}

VB (array.frm)
--------------
VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Array Tester"
   ClientHeight    =   3165
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3165
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.ComboBox Combo1
      Height          =   315
      Left            =   2640
      TabIndex        =   4
      Text            =   "0"
      Top             =   360
      Width           =   1455
   End
   Begin VB.CommandButton Command1
      Caption         =   "Select Byte"
      Height          =   495
      Left            =   1200
      TabIndex        =   1
      Top             =   2400
      Width           =   2295
   End
   Begin VB.TextBox Text1
      Height          =   495
      Left            =   2640
      TabIndex        =   0
      Text            =   "0"
      Top             =   1200
      Width           =   1455
   End
   Begin VB.Label Label1
      Alignment       =   1  'Right Justify
      Caption         =   "Byte at selected index"
      Height          =   495
      Left            =   480
      TabIndex        =   3
      Top             =   1200
      Width           =   1815
   End
   Begin VB.Label Se
      Alignment       =   1  'Right Justify
      Caption         =   "Select Index"
      Height          =   375
      Left            =   360
      TabIndex        =   2
      Top             =   360
      Width           =   1935
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim oArray As Object
Dim arr(5) As Byte

Private Sub Command1_Click()
  Dim x As Integer
  x = Val(Combo1.Text)
  Text1 = oArray.pickByte(arr, x)
End Sub

Private Sub Form_Load()
  Set oArray = CreateObject("ArrayBean2.Bean")
  Combo1.AddItem "0"
  Combo1.AddItem "1"
  Combo1.AddItem "2"
  Combo1.AddItem "3"
  Combo1.AddItem "4"

  arr(0) = 0
  arr(1) = 1
  arr(2) = 2
  arr(3) = 3
  arr(4) = 4
End Sub


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
If you can, use higher level abstraction classes (i.e. String)
(Review ID: 184159) 
======================================================================



SAP has seen this problem in their development. After trying Tiger, they
still saw this issue:

-------------------------------------------------------------------
I've installed now the Tiger Version J2SE 5.0.

The following is working:
1. to pass a single byte and a byte array from outer world to Java via
   the Axbridge
2. to get a single byte back from Java to outer world via Axbridge

But there is still the following problem:
1. to get a byte array back from Java to outer world via Axbridge
   Error:
    either 'type mismatch' if you define the result as byte array
    like in VB:  'Dim result() as Byte'
    or if you define 'Dim result as Variant' you will get an
    'unsupported variant type'. A cast will result in 'type mismatch'
    or 'automation error'.
------------------------------------------------------------------- 

So there are two problems:

1. With Tiger, there still seems to be one case where it does not 
   work.

2. SAP really needs this for 1.4.2, so the fix would need to be backported
   to that release.

###@###.### 2004-08-11








                                    

Comments
EVALUATION

The Array element types are not matched correctly to select the correct method
###@###.### 2003-08-04

------------------------------------

For the following problem present in 1.4.2 and tiger:
* to get a byte array back from Java to outer world via Axbridge

--> the returned object in VB is a Variant but the contents of the Variant are shown as <Unsupprted variant type>.

In axbridge, we are using VT_I1(signed one byte) as VARTYPE for bytes in VARIANT. And this VARTYPE is shown as Unsupprted variant type in VB. I wrote a simple COM component to verify this (attaching with bugreport).

Now we have the choice of using either VT_UI1(unsigned one byte) or VT_I2(signed two bytes).

But these two also have some problems:
VT_UI1:
======
As this is unsigned byte we won't be able to pass negative bytes from java world to VB. 

VT_I2
=====
This won't be having negative number problem but we will be using one extra byte and we will see the returned value as 'Integer' in VB instead of byte.

###@###.### 2004-08-19


----------------------------------------

There is an official statement form Microsoft that VT_I1 is not supported in VB.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/ctrans_8nhv.asp

The portion of the table from the above link:

C++                 Visual Basic       Java               Contains  
-------------------------------------------------------------------------  
signed char       Not supported        byte           1-byte signed integer
                                                       (VT_I1, [T]) 
unsigned char       Byte            Not supported     1-byte unsigned integer
                                                      (VT_UI1, [V][T][P][S])
unsigned char      Character         char             2-byte Unicode character
                                                       (VT_UI2, [T][P])
...

So our axbridge is mapping the 'java byte' corretly to VT_I1 which is not supported in VB and it is a limitation of VB.

Hence this problem cannot be fixed in Java. Customer will have to use other data types to resolve this problem.

###@###.### 2004-08-20
                                     
2004-08-20
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
1.4.2_07
tiger

FIXED IN:
1.4.2_07
tiger

INTEGRATED IN:
tiger
tiger-b16


                                     
2004-10-02



Hardware and Software, Engineered to Work Together