在AS400 / Java上创建Mac对象时出现StackOverFlowError

时间:2010-06-17 14:43:27

标签: java ibm-midrange jce java1.4

我是AS400-Java编程的新手。我正在尝试创建我的第一个程序来测试消息验证代码(MAC)的实现。我正在尝试使用HMACSHA1哈希函数。我的(Java 1.4)程序在开发框(V5R4)上运行良好。但是在QA框(V5R3)上非常失败。我的计划如下:

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


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'};


}

这个程序编译得很好,并在我的win-xp客户端和我的开发盒上获得正确的响应。但是,在QA框中出现以下错误失败:

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)

我已经验证了java.security文件,并且对应于jce文件的条目都可以。 DMPJVM命令给出了以下响应:

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

有人可以告诉我吗?

非常感谢, 人员Prasanna

1 个答案:

答案 0 :(得分:1)

问题似乎是

at java.io.Os400FileSystem.list(Native method)
at java.io.File.list(File.java:922)

Mac.getInstance()代码需要读取由Os400FileSystem.list()方法完成的文件夹(File.list)。显然该文件夹太大了。

您需要检查的第一件事是机器在PTF上是最新的。如果问题仍然存在,那么尝试给你的进程更多的内存(JAVA / RUNJVA命令的参数),看看你是否只有一点点内存。默认值从V5R3增加到V5R4。