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 194131 - getAppletShareableInterface() throws an exception in debugger.
Summary: getAppletShareableInterface() throws an exception in debugger.
Status: RESOLVED WONTFIX
Alias: None
Product: javacard
Classification: Unclassified
Component: Java Card (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P2 normal (vote)
Assignee: _ tboudreau
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-07 20:18 UTC by Benjamin_Gittins
Modified: 2011-02-16 11:21 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Full project and source code ready for bug hunting. (44.14 KB, application/octet-stream)
2011-01-07 20:18 UTC, Benjamin_Gittins
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin_Gittins 2011-01-07 20:18:03 UTC
Created attachment 104797 [details]
Full project and source code ready for bug hunting.

I have created two applets:

ST_Client is a Java Card 3.0 Extended Applet  ( No choice, selected to get around Packager false-error that java card classic does not support more than 1 package in a .CAP file. Go look at the 2003 Java card 2 example sample code demonstrating the use of Sharable )

ST_Server is a Java Card 3.0 Classic Applet

Source code and project files attached to this posting.

They are absolute minimal test applets. 

---------
Uncompress the .zip

Open Project "ST_Client" in the NetBeans IDE
Open Project "ST_Server" in the NetBeans IDE

Right click ST_Server -> Clean and Build 
Right click ST_Client -> Clean and Build

Right click ST_Server -> Reload 
Right click ST_Server -> Create Instance

Right click ST_Client -> Reload 
Right click ST_Client -> Create Instance
Right click ST_Client / APDUIO Scripts / st_client.scr -> Send to Card

OUTPUT:

Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00 
CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 07, f2, 32, 44, b5, 1a, 01, 01, Le: 00, SW1: 90, SW2: 00
CLA: 80, INS: ca, P1: 00, P2: 00, Lc: 01, 00, Le: 01, 02, SW1: 90, SW2: 00

LE 01, 01, SW1:90 = OKAY
LE 01, 02, SW1:90 = OKAY
LE 01, 03, SW1:90 = getAppletShareableInterface() returned NULL without throwing an exception.

All good so far..  We can run the code if we are not in a debugger.

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

Same applies if we run the ST_Server code in a debugger

However... for ST_Client...

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

Right click ST_Client -> Set as Main Project 
Open ST_Client.java
Set breakpoint on line 60
Menu bar | Debug | Debug Main Project
wait for it to enter debugger.

Right click ST_Server -> Reload 
Right click ST_Server -> Create Instance

we now have both the client and server installed.
Now step through the ST_Client code...
when we step through line 94  we get...


Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00 
CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 07, f2, 32, 44, b5, 1a, 01, 01, Le: 00, SW1: 90, SW2: 00
CLA: 80, INS: ca, P1: 00, P2: 00, Lc: 01, 00, Le: 00, SW1: 6f, SW2: 00

Le: 00, SW1: 6f, SW2: 00  <--- getAppletShareableInterface() threw an exception.

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

I cannot test in 6.9 and 7.0 beta because of the problems with the applet configuration panel.
Comment 1 Benjamin_Gittins 2011-01-08 20:24:07 UTC
I have done some additional testing.
The problem is very particular.

The problem is not the call to  JCSystem.getAppletShareableInterfaceObject(), but in the subsequent type casting operation.

So by rewriting line 94 in ST_Client.java :

            server = (ST_ServerShareable)JCSystem.getAppletShareableInterfaceObject(x, (byte) 0);

to
            Shareable sio = JCSystem.getAppletShareableInterfaceObject(x, (byte) 0);  // works
            server = (ST_ServerShareable)sio; // crashes here.

Furthermore, this problem only occurs if the ST_Client (Java Card 3.0 connected) requests getAppletSIO from ST_Server (Java Card 3.0 classic) while debugging.  It works if I just run the code outside of the debugger. 

I have other development code which makes the same type of call (getAppletSIO) from Java Card 3.0 classic to Java Card 3.0 connected and it does not crash during debugging in the IDE.

Hope that helps identify the fault causing this error.
Comment 2 Benjamin_Gittins 2011-01-16 13:03:29 UTC
I have done some additional testing.

It is possible the problem is not with the debugger itself. Rather, it appears that the ORDER in which the applets are loaded into the java card runtime is the critical issue.

For instance, if the client applet is loaded before the server applet, sending the script to the smart cards results in a failure. This load order (client then server) happens when we describing debugging the client code. 

I cannot think of any obvious reason why this should cause a problem.
The two applets load without talking to each other.
The script invocation is the first time a shareable interface is created.

Furthermore, in other code i have, it does not matter if the client, or the server call JCSystem.getAppletShareableInterfaceObject. If the client is installed before the server applet, the code crashes.

More specifically: This seems to be an issue related to calls between Java Card 3 classic and Java Card 3 connected editions. If connected applet is installed first, and then a connected and classic applet try to talk with each other, the system fails. Otherwise, if classic applet is installed first, all works without problem. 

[ i am going to try and see if i can work around the problem for now by using both connected editions, give the classic edition fails to compile javacard 2.x legacy code that compiles source code in more than one package correctly ].
Comment 3 Benjamin_Gittins 2011-01-16 13:26:37 UTC
>> [ i am going to try and see if i can work around the problem for now by using both connected editions, give the classic edition fails to compile javacard 2.x legacy code that compiles source code in more than one package correctly ].

I have now used both Java Card Connected edition for both applets. The problem continues to be order dependent. I am running out of suggestions for possible sources of the fault. It will need to be looked at by someone that has lower-level access inside what is going on inside the netbeans IDE and java card runtime environment. 

--- Side note, regarding the operating system, I am running the smart card environment entirely under  Windows XP, and not Mac OS X.
Comment 4 Adam Sotona 2011-02-16 11:21:03 UTC
This issue cannot be fixed in NetBeans. It is rather related to the runtime.