StackOverFlowError while creating Mac object on AS400/Java

Posted by Prasanna K Rao on Stack Overflow See other posts from Stack Overflow or by Prasanna K Rao
Published on 2010-06-17T14:43:27Z Indexed on 2010/06/18 9:43 UTC
Read the original article Hit count: 1110

Filed under:
|
|
|

Hello all,

I am a newbie to AS400-Java programming. I am trying to create my first program to test the implementation of Message Authentication Code (MAC). I am trying to use the HMACSHA1 hash function. My (Java 1.4) program runs fine on a dev box (V5R4).But fails terribly on the QA box (V5R3). My program is as below:

=====================================================


import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
import java.security.Provider;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.SecretKey;

public class Test01
{
 private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";

 public static void main (String [] arguments)
 {
  byte[] key = { 1,2,3,4,5,6,7,8};
  SecretKeySpec SHA1key = new SecretKeySpec(key, "HmacSHA1");
  Mac hmac;
  String strFinalRslt = "";

  try {
 hmac = Mac.getInstance("HmacSHA1");
 hmac.init(SHA1key);
 byte[] result = hmac.doFinal();
    strFinalRslt = toHexString(result);

  }catch (NoSuchAlgorithmException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
  }catch (InvalidKeyException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
  }catch(StackOverflowError e){
 e.printStackTrace();
  }
  System.out.println(strFinalRslt);
  System.out.println("All done!!!");
 }

 public static byte[] fromHexString ( String s )
 {
  int stringLength = s.length();
  if ( (stringLength & 0x1) != 0 )
  {
   throw new IllegalArgumentException ( "fromHexString requires an even number of hex characters" );
  }
  byte[] b = new byte[stringLength / 2];

  for ( int i=0,j=0; i>> 4] );

  //look up low nibble char
  sb.append( hexChar [b[i] & 0x0f] );
 }
 return sb.toString();
}

static char[] hexChar = {
'0' , '1' , '2' , '3' ,
'4' , '5' , '6' , '7' ,
'8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f'};


}

This program compiles fine and gets the correct response on my win-xp client and also my dev box. But, fails with the following error on the QA box:

java.lang.StackOverflowError
    at java.lang.Throwable.(Throwable.java:180)
    at java.lang.Error.(Error.java:37)
    at java.lang.StackOverflowError.(StackOverflowError.java:24)
    at java.io.Os400FileSystem.list(Native method)
    at java.io.File.list(File.java:922)
    at javax.crypto.b.e(Unknown source)
    at javax.crypto.b.a(Unknown source)
    at javax.crypto.b.c(Unknown source)
    at javax.crypto.b£0.run(Unknown source)
    at javax.crypto.b.(Unknown source)
    at javax.crypto.Mac.getInstance(Unknown source)

I have verified the java.security file and entry corresponding to the jce files are all ok. The DMPJVM command gives me the following response:

Thu Jun 03 12:25:34 E
Java Virtual Machine Information  016822/QPGMR/11111
........................................................................
. Classpath                                                            .
........................................................................
java.version=1.4
sun.boot.class.path=/QIBM/ProdData/OS400/Java400/jdk/lib/jdkptf14.zip:/QIBM
/ProdData/OS400/Java400/ext/ibmjssefw.jar:/QIBM/ProdData/CAP/ibmjsseprovide
r.jar:/QIBM/ProdData/OS400/Java400/ext/ibmjsseprovider2.jar:/QIBM/ProdData/
OS400/Java400/ext/ibmpkcs11impl.jar:/QIBM/ProdData/CAP/ibmjssefips.jar:/QIB
M/ProdData/OS400/Java400/jdk/lib/IBMiSeriesJSSE.jar:/QIBM/ProdData/OS400/Ja
va400/jdk/lib/jce.jar:/QIBM/ProdData/OS400/Java400/jdk/lib/jaas.jar:/QIBM/P
rodData/OS400/Java400/jdk/lib/ibmcertpathfw.jar:/QIBM/ProdData/OS400/Java40
0/jdk/lib/ibmcertpathprovider.jar:/QIBM/ProdData/OS400/Java400/ext/ibmpkcs.
jar:/QIBM/ProdData/OS400/Java400/jdk/lib/ibmjgssfw.jar:/QIBM/ProdData/OS400
/Java400/jdk/lib/ibmjgssprovider.jar:/QIBM/ProdData/OS400/Java400/jdk/lib/s
ecurity.jar:/QIBM/ProdData/OS400/Java400/jdk/lib/charsets.jar:/QIBM/ProdDat
a/OS400/Java400/jdk/lib/resources.jar:/QIBM/ProdData/OS400/Java400/jdk/lib/
rt.jar:/QIBM/ProdData/OS400/Java400/jdk/lib/sunrsasign.jar:/QIBM/ProdData/O
S400/Java400/ext/IBMmisc.jar:/QIBM/ProdData/Java400/
java.class.path=/myhome/lib/commons-codec-1.3.jar:/myhome/lib/commons-httpc
lient-3.1.jar:/myhome/lib/commons-logging-1.1.jar:/myhome/lib/log4j-1.2.15.jar:/myhome/lib/log4j-core.jar
;
java.ext.dirs=/QIBM/ProdData/OS400/Java400/jdk/lib/ext:/QIBM/UserData/Java4
00/ext:/QIBM/ProdData/Java400/jdk14/lib/ext
java.library.path=/QSYS.LIB/ROBOTLIB.LIB:/QSYS.LIB/QTEMP.LIB:/QSYS.LIB/ODIP
GM.LIB:/QSYS.LIB/QGPL.LIB
........................................................................
. Garbage Collection                                                   .
........................................................................
Garbage collector parameters
   Initial size: 16384 K
   Max size: 240000000 K
Current values
   Heap size: 437952 K
   Garbage collections: 58
Additional values
   JIT heap size: 53824 K
   JVM heap size: 55752 K
   Last GC cycle time: 1333 ms
........................................................................
. Thread information                                                   .
........................................................................
Information for 4 thread(s) of 4 thread(s) processed
Thread:  00000004 Thread-0
  TDE:  B00380000BAA0000
  Thread priority: 5
  Thread status: Running
  Thread group: main
  Runnable: java/lang/Thread
 Stack:
    java/io/Os400FileSystem.list(Ljava/io/File;)[Ljava/lang/String;+0 (Os400FileSystem.java:0)
    java/io/File.list()[Ljava/lang/String;+19 (File.java:922)
    javax/crypto/b.e()[B+127 (:0)
    javax/crypto/b.a(Ljava/security/cert/X509Certificate;)V+7 (:0)
    javax/crypto/b.access$500(Ljava/security/cert/X509Certificate;)V+1 (:0)
    javax/crypto/b$0.run()Ljava/lang/Object;+98 (:0)
    javax/crypto/b.()V+507 (:0)
    javax/crypto/Mac.getInstance(Ljava/lang/String;)Ljavax/crypto/Mac;+10 (:0)
 Locks:
    None
Thread:  00000007 jitcompilethread
  TDE:  B00380000BD58000
  Thread priority: 5
  Thread status: Java wait
  Thread group: system
  Runnable: java/lang/Thread
 Stack:
    None
 Locks:
    None
Thread:  00000005 Reference Handler
  TDE:  B00380000BAAC000
  Thread priority: 10
  Thread status: Waiting
  Wait object: java/lang/ref/Reference$Lock
  Thread group: system
  Runnable: java/lang/ref/Reference$ReferenceHandler
 Stack:
    java/lang/Object.wait()V+1 (Object.java:452)
    java/lang/ref/Reference$ReferenceHandler.run()V+47 (Reference.java:169)
 Locks:
    None
Thread:  00000006 Finalizer
  TDE:  B00380000BAB3000
  Thread priority: 8
  Thread status: Waiting
  Wait object: java/lang/ref/ReferenceQueue$Lock
  Thread group: system
  Runnable: java/lang/ref/Finalizer$FinalizerThread
 Stack:
    java/lang/ref/ReferenceQueue.remove(J)Ljava/lang/ref/Reference;+43 (ReferenceQueue.java:111)
    java/lang/ref/ReferenceQueue.remove()Ljava/lang/ref/Reference;+1 (ReferenceQueue.java:127)
    java/lang/ref/Finalizer$FinalizerThread.run()V+3 (Finalizer.java:171)
 Locks:
    None
........................................................................
. Class loader information                                             .
........................................................................
0 Default class loader
1 sun/reflect/DelegatingClassLoader
2 sun/misc/Launcher$ExtClassLoader
........................................................................
. GC heap information                                                  .
........................................................................
 Loader     Objects      Class name
 ------     -------      ----------
 0          1493         [C
 0          2122181      java/lang/String
 0          47           [Ljava/util/Hashtable$Entry;
 0          68           [Ljava/lang/Object;
 0          1016         java/lang/Class
 0          31           java/util/HashMap
 0          37           java/util/Hashtable
 0          2            java/lang/ThreadGroup
 0          2            java/lang/RuntimePermission
 0          2            java/lang/ref/ReferenceQueue$Null
 0          5            java/lang/ref/ReferenceQueue
 0          50           java/util/Vector
 0          4            java/util/Stack
 0          3            sun/misc/SoftCache
 0          1            [Ljava/lang/ThreadGroup;
 0          5            [Ljava/io/ObjectStreamField;
 0          1            sun/reflect/ReflectionFactory
 0          7            java/lang/ref/ReferenceQueue$Lock
 0          10           java/lang/Object
 0          1            java/lang/String$CaseInsensitiveComparator
 0          1            java/util/Hashtable$EmptyEnumerator
 0          1            java/util/Hashtable$EmptyIterator
 0          33           [Ljava/util/HashMap$Entry;
 0          19210        [J
 0          1            sun/nio/cs/StandardCharsets
 0          5            java/util/TreeMap
 0          1075         java/util/TreeMap$Entry
 0          469          [Ljava/lang/String;
 0          1            java/lang/StringBuffer
 0          2            java/io/FileInputStream
 0          2            java/io/FileOutputStream
 0          2            java/io/BufferedOutputStream
 0          1            java/lang/reflect/ReflectPermission
 0          1            [[Ljava/lang/ref/SoftReference;
 0          2            [Ljava/lang/ref/SoftReference;
 0          2            sun/nio/cs/Surrogate$Parser
 0          3            sun/misc/Signal
 0          1            [Ljava/io/File;
 0          6            java/io/File
 0          1            java/util/BitSet
 0          17           sun/reflect/NativeConstructorAccessorImpl
 0          2            java/net/URLClassLoader$ClassFinder
 0          12           java/util/ArrayList
 0          32           java/io/RandomAccessFile
 0          16           java/lang/Thread
 0          1            java/lang/ref/Reference$ReferenceHandler
 0          1            java/lang/ref/Finalizer$FinalizerThread
 0          266          [B
 0          2            java/util/Properties
 0          71           java/lang/ref/Finalizer
 0          2            com/ibm/nio/cs/DirectEncoder
 0          38           java/lang/reflect/Constructor
 0          33           java/util/jar/JarFile
 0          19200        java/lang/StackOverflowError
 0          5            java/security/AccessControlContext
 0          2            [Ljava/lang/Thread;
 0          4            java/lang/OutOfMemoryError
 0          1065         java/util/Hashtable$Entry
 0          1            java/io/BufferedInputStream
 0          2            java/io/PrintStream
 0          2            java/io/OutputStreamWriter
 0          428          [I
 0          3            java/lang/ClassLoader$NativeLibrary
 0          25           java/util/Locale
 0          3            sun/misc/URLClassPath
 0          30           java/util/zip/Inflater
 0          612          java/util/HashMap$Entry
 0          2            java/io/FilePermission
 0          10           java/io/ObjectStreamField
 0          1            java/security/BasicPermissionCollection
 0          2            java/security/ProtectionDomain
 0          1            java/lang/Integer$1
 0          1            java/lang/ref/Reference$Lock
 0          1            java/lang/Shutdown$Lock
 0          1            java/lang/Runtime
 0          36           java/io/FileDescriptor
 0          1            java/lang/Long$1
 0          202          java/lang/Long
 0          3            java/lang/ThreadLocal
 0          3            java/nio/charset/CodingErrorAction
 0          2            java/nio/charset/CoderResult
 0          1            java/nio/charset/CoderResult$1
 0          1            java/nio/charset/CoderResult$2
 0          1            sun/misc/Unsafe
 0          2            java/nio/ByteOrder
 0          1            java/io/Os400FileSystem
 0          3            java/lang/Boolean
 0          1            java/lang/Terminator$1
 0          23           java/lang/Integer
 0          2            sun/misc/NativeSignalHandler
 0          1            sun/misc/Launcher$Factory
 0          1            sun/misc/Launcher
 0          53           [Ljava/lang/Class;
 0          1            java/lang/reflect/ReflectAccess
 0          18           sun/reflect/DelegatingConstructorAccessorImpl
 0          1            sun/net/www/protocol/file/Handler
 0          3            java/util/HashSet
 0          3            sun/net/www/protocol/jar/Handler
 0          1            java/util/jar/JavaUtilJarAccessImpl
 0          1            java/net/UnknownContentHandler
 0          2            [Ljava/security/Principal;
 0          10           [Ljava/security/cert/Certificate;
 0          2            sun/misc/AtomicLongCSImpl
 0          3            sun/reflect/DelegatingMethodAccessorImpl
 0          1            sun/security/util/ByteArrayLexOrder
 0          1            sun/security/util/ByteArrayTagOrder
 0          7            sun/security/x509/CertificateVersion
 0          7            sun/security/x509/CertificateSerialNumber
 0          7            sun/security/x509/SerialNumber
 0          7            sun/security/x509/CertificateAlgorithmId
 0          7            sun/security/x509/CertificateIssuerName
 0          60           sun/security/x509/RDN
 0          60           [Lsun/security/x509/AVA;
 0          67           sun/security/util/DerInputStream
 0          3            [Ljava/math/BigInteger;
 0          2            com/ibm/nio/cs/Converter
 0          2            sun/nio/cs/StreamEncoder$CharsetSE
 0          35           java/lang/ref/SoftReference
 0          2            java/nio/HeapByteBuffer
 0          2            java/io/BufferedWriter
 0          33           sun/misc/URLClassPath$JarLoader
 0          4            java/lang/ThreadLocal$ThreadLocalMap$Entry
 0          76           java/net/URL
 0          1            sun/misc/Launcher$ExtClassLoader
 0          1            sun/misc/Launcher$AppClassLoader
 0          4            java/lang/Throwable
 0          7            java/lang/reflect/Method
 0          2            sun/misc/URLClassPath$FileLoader
 0          2            java/security/CodeSource
 0          2            java/security/Permissions
 0          2            java/io/FilePermissionCollection
 0          1            java/lang/ThreadLocal$ThreadLocalMap
 0          1            javax/crypto/spec/SecretKeySpec
 0          17           java/util/jar/Attributes$Name
 0          1            [Ljava/lang/ThreadLocal$ThreadLocalMap$Entry;
 0          1            java/security/SecureRandom
 0          2            sun/security/provider/Sun
 0          1            java/util/jar/JarFile$JarFileEntry
 0          1            java/util/jar/JarVerifier
 0          3            sun/reflect/NativeMethodAccessorImpl
 0          116          sun/security/util/ObjectIdentifier
 0          1            java/lang/Package
 0          2            [S
 0          104          java/math/BigInteger
 0          20           sun/security/x509/AlgorithmId
 0          14           sun/security/x509/X500Name
 0          14           [Lsun/security/x509/RDN;
 0          60           sun/security/x509/AVA
 0          67           sun/security/util/DerValue
 0          67           sun/security/util/DerInputBuffer
 0          21           sun/security/x509/AVAKeyword
 0          6            sun/security/x509/X509CertImpl
 0          7            sun/security/x509/X509CertInfo
 0          1            [Lsun/security/util/ObjectIdentifier;
 0          1            [[Ljava/lang/Byte;
 0          3            [[B
 0          7            sun/security/provider/DSAPublicKey
 0          7            sun/security/x509/AuthorityKeyIdentifierExtension
 0          12           [Ljava/lang/Byte;
 0          14           java/lang/Byte
 0          7            sun/security/x509/CertificateSubjectName
 0          7            sun/security/x509/CertificateX509Key
 0          14           sun/security/x509/KeyIdentifier
 0          4            [Z
 0          5            sun/text/Normalizer$Mode
 0          7            sun/security/x509/CertificateValidity
 0          14           java/util/Date
 0          7            sun/security/provider/DSAParameters
 0          7            sun/security/util/BitArray
 0          7            sun/security/x509/CertificateExtensions
 0          7            java/security/AlgorithmParameters
 0          7            sun/security/x509/SubjectKeyIdentifierExtension
 0          5            sun/security/x509/BasicConstraintsExtension
 0          2            sun/security/x509/KeyUsageExtension
 0          1            sun/text/CompactCharArray
 0          1            sun/text/CompactByteArray
 0          1            sun/net/www/protocol/jar/JarFileFactory
 0          1            java/util/Collections$EmptySet
 0          1            java/util/Collections$EmptyList
 0          1            java/util/Collections$ReverseComparator
 0          1            com/ibm/security/jgss/i18n/PropertyResource
 0          1            javax/crypto/b$0
 0          1            sun/security/provider/X509Factory
 0          1            sun/reflect/BootstrapConstructorAccessorImpl
 1          1            sun/reflect/GeneratedConstructorAccessor3202134454
 2          1            com/ibm/crypto/provider/IBMJCE
 0          6            java/util/ResourceBundle$LoaderReference
 0          1            [Lsun/security/x509/NetscapeCertTypeExtension$MapEntry;
 0          1            com/sun/rsajca/Provider
 0          1            com/ibm/security/cert/IBMCertPath
 0          1            com/ibm/as400/ibmonly/net/ssl/Provider
 0          1            com/ibm/jsse/IBMJSSEProvider
 0          1            com/ibm/security/jgss/IBMJGSSProvider
 0          5            org/ietf/jgss/Oid
 0          1            java/util/PropertyResourceBundle
 0          7            java/util/ResourceBundle$ResourceCacheKey
 0          2            sun/net/www/protocol/jar/URLJarFile
 0          6            sun/misc/SoftCache$ValueCell
 0          1            java/util/Random
 0          1            java/util/Collections$EmptyMap
 0          112          com/ibm/security/util/ObjectIdentifier
 0          5            java/security/Security$ProviderProperty
 0          1            java/security/cert/CertificateFactory
 0          1            sun/security/provider/SecureRandom
 0          2            java/security/MessageDigest$Delegate
 0          2            sun/security/provider/SHA
 0          1            sun/util/calendar/ZoneInfo
 0          4            com/ibm/security/x509/X500Name
 0          2            [Ljava/security/cert/X509Certificate;
 0          1            sun/reflect/DelegatingClassLoader
 0          1            sun/security/x509/NetscapeCertTypeExtension
 0          7            sun/security/x509/NetscapeCertTypeExtension$MapEntry
 0          3            [[Ljava/lang/String;
 0          3            java/util/Arrays$ArrayList
 0          7            com/ibm/security/x509/NetscapeCertTypeExtension$MapEntry
 0          1            com/ibm/security/validator/EndEntityChecker
 0          1            java/util/AbstractList$Itr
 0          1            com/ibm/security/util/ByteArrayLexOrder
 0          1            com/ibm/security/util/ByteArrayTagOrder
 0          18           [Lcom/ibm/security/x509/AVA;
 0          18           com/ibm/security/util/DerInputStream
 0          5            com/ibm/security/util/text/Normalizer$Mode
 0          1            com/ibm/security/validator/SimpleValidator
 0          1            [Lcom/ibm/security/x509/NetscapeCertTypeExtension$MapEntry;
 0          4            [Lcom/ibm/security/x509/RDN;
 0          1            java/util/Hashtable$Enumerator
 0          4            java/util/LinkedHashMap$Entry
 0          1            sun/text/resources/LocaleElements
 0          1            sun/text/resources/LocaleElements_en
 0          22           com/ibm/security/x509/AVAKeyword
 0          4            javax/security/auth/x500/X500Principal
 0          18           com/ibm/security/x509/RDN
 0          18           com/ibm/security/x509/AVA
 0          18           com/ibm/security/util/DerInputBuffer
 0          18           com/ibm/security/util/DerValue
 0          1            com/ibm/security/util/text/CompactCharArray
 0          1            com/ibm/security/util/text/CompactByteArray
 0          2            java/util/LinkedHashMap
 0          1            java/net/InetAddress$1
 0          2            [Ljava/net/InetAddress;
 0          2            java/net/InetAddress$Cache
 0          1            java/net/Inet4AddressImpl
 0          3            java/net/Inet4Address
 0          2            java/net/InetAddress$CacheEntry
........................................................................
. Global registry information                                          .
........................................................................
 Loader     Objects      Class name
 ------     -------      ----------
 0          23           [C
 0          1017         java/lang/Class
 0          1            java/lang/ref/Reference$ReferenceHandler
 0          1            java/lang/ref/Finalizer$FinalizerThread
 0          1            sun/misc/Launcher$AppClassLoader
 0          32           java/io/RandomAccessFile
 0          32           [B

Can someone please advise me?

Thanks a lot, Prasanna

© Stack Overflow or respective owner

Related posts about java

Related posts about as400