Hi @FrankF ,
The issue is not the allocation of the array but its assignment to the class variable 'globalArray'. If you remove the assignment you will see that it works. Javacard specification makes the following statement about Global Arrays.
A global array can be accessed from any applet context. References to global arrays cannot be stored in class variables or instance variables or array components. (See Runtime Environment Specification, Java Card Platform, Classic Edition, section 6.2.2 for details)
The code therefore can be made to work by assigning the globalArray object to an automatic variable as below:
package com.xyz.test;
import javacard.framework.*;
public class GlobalArray extends Applet {
public static void install(byte[] bArray, short bOffset, byte bLength) {
new com.xyz.test.GlobalArray().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public void process(APDU apdu) {
if (selectingApplet()) { return; }
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x00:
Object globalArray;
try {
globalArray = (byte[]) JCSystem.makeGlobalArray(JCSystem.ARRAY_TYPE_BYTE, (short) 8);
} catch (SecurityException e) {
ISOException.throwIt((short) 0x6ff1);
}
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
Hope that helps,
Have a great day,
Kan
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------