From c6d212fa2e392fe0e2897c8996faf2e2b2a6770a Mon Sep 17 00:00:00 2001 Date: Wed, 4 Jan 2023 20:47:39 +0800 Subject: Add Fast serializer testcase --- .../TestDescription.java | 30 + .../noargctor/TestDescription.java | 36 + .../NPEProvoker/TestDescription.java | 25 + .../TestDescription.java | 26 + .../PutField/TestDescription.java | 42 + .../arraySuidConflict/TestDescription.java | 27 + .../auditStreamSubclass/TestDescription.java | 25 + .../available/TestDescription.java | 22 + .../backRefCNFException/TestDescription.java | 28 + .../TestDescription.java | 22 + .../badSerialVersionUID/TestDescription.java | 23 + .../badSubstByReplace/TestDescription.java | 21 + .../checkModifiers/TestDescription.java | 27 + .../FastSerializer/class/NonSerialA_1/A.java | 5 + .../FastSerializer/class/NonSerialA_2/A.java | 6 + .../io/FastSerializer/class/SerialA_1/A.java | 7 + .../io/FastSerializer/class/SerialA_2/A.java | 10 + .../io/FastSerializer/class/SerialA_3/A.java | 10 + .../FastSerializer/class/TestDescription.java | 28 + .../io/FastSerializer/class/TestEntry.java | 77 ++ .../classDescGetField/TestDescription.java | 25 + .../io/FastSerializer/classDescHooks/Foo.ser | Bin 0 -> 271 bytes .../classDescHooks/TestDescription.java | 51 ++ .../classLoader/classLoaderExtern.java | 137 +++ .../classLoader/classLoaderSer.java | 124 +++ .../clearHandleTable/TestDescription.java | 21 + .../cloneArray/TestDescription.java | 22 + .../TestDescription.java | 21 + .../TestDescription.java | 25 + .../defaultDataEnd/TestDescription.java | 22 + .../TestDescription.java | 22 + .../java/io/FastSerializer/diffExtern/Foo.ser | Bin 0 -> 87 bytes .../io/FastSerializer/diffExtern/Foo2.ser | Bin 0 -> 79 bytes .../FastSerializer/diffExtern/addField.java | 93 ++ .../FastSerializer/diffExtern/addclass.java | 96 ++ .../diffExtern/changeModifier.java | 84 ++ .../FastSerializer/diffExtern/deletField.java | 86 ++ .../diffExtern/removeStatic.java | 85 ++ .../diffExtern/staticField.java | 86 ++ .../java/io/FastSerializer/diffSer/Foo.ser | Bin 0 -> 46 bytes .../java/io/FastSerializer/diffSer/Foo4.ser | Bin 0 -> 75 bytes .../io/FastSerializer/diffSer/addField.java | 78 ++ .../io/FastSerializer/diffSer/addclass.java | 91 ++ .../diffSer/changeModifier.java | 72 ++ .../io/FastSerializer/diffSer/deletField.java | 71 ++ .../FastSerializer/diffSer/removeStatic.java | 63 ++ .../FastSerializer/diffSer/staticField.java | 63 ++ .../TestDescription.java | 33 + .../dynamicProxy/dynamicExtern.java | 131 +++ .../dynamicProxy/dynamicSer.java | 107 +++ .../enum/array/TestDescription.java | 21 + .../enum/basic/TestDescription.java | 21 + .../enum/classObject/TestDescription.java | 21 + .../constantSubclasses/TestDescription.java | 27 + .../TestDescription.java | 21 + .../TestDescription.java | 21 + .../mismatchedTypecode/TestDescription.java | 22 + .../enum/missingConstant/TestDescription.java | 27 + .../enum/unshared/TestDescription.java | 21 + .../AddedSuperClass/TestDescription.java | 42 + .../RenamePackage/TestDescription.java | 33 + .../extension/ExtendedObjectInputStream.java | 56 ++ .../RenamePackage/install/SerialDriver.java | 117 +++ .../RenamePackage/test/SerialDriver.java | 114 +++ .../expectedStackTrace/TestDescription.java | 25 + .../explicitCNFException/TestDescription.java | 22 + .../failureAtomicity/Bar.template | 64 ++ .../failureAtomicity/Foo.template | 62 ++ .../failureAtomicity/SerialRef.java | 25 + .../failureAtomicity/TestDescription.java | 24 + .../finalFields/TestDescription.java | 20 + .../getSuidClinitError/TestDescription.java | 22 + .../illegalHandle/TestDescription.java | 20 + .../illegalHandle/negativeHandle.ser | Bin 0 -> 15 bytes .../illegalHandle/tooHighHandle.ser | Bin 0 -> 15 bytes .../inactiveRegistration/TestDescription.java | 21 + .../innerClass/innerExtern.java | 107 +++ .../innerClass/innerSerial.java | 85 ++ .../java/io/FastSerializer/logging.properties | 64 ++ .../longString/TestDescription.java | 22 + .../io/FastSerializer/longString/mesg.ser | Bin 0 -> 29 bytes .../lookupAnyInvocation/TestDescription.java | 22 + .../lookupInterfaceDesc/TestDescription.java | 21 + .../maskSyntheticModifier/Foo.class | Bin 0 -> 667 bytes .../maskSyntheticModifier/Foo.java | 19 + .../TestDescription.java | 24 + .../TestDescription.java | 20 + .../modifyStaticFields/TestDescription.java | 21 + .../nestedReplace/TestDescription.java | 25 + .../TestDescription.java | 23 + .../nonserializable/TestDescription.java | 21 + .../normalExter/normalClassExternalize.java | 81 ++ .../normalSer/ArraySerialize.java | 67 ++ .../normalSer/EnumSerialize.java | 68 ++ .../normalSer/StringSerialize.java | 57 ++ .../normalSer/normalClassSerialize.java | 69 ++ .../notAvailable/TestDescription.java | 23 + .../TestDescription.java | 23 + .../FastSerializer/nullStream/nullExtern.java | 91 ++ .../FastSerializer/nullStream/nullSerial.java | 79 ++ .../oldTests/TestDescription.java | 121 +++ .../optionalDataEnd/TestDescription.java | 22 + .../overWriteAnnotateClass.java | 121 +++ .../overWriteExtern/overWriteReadResolve.java | 100 +++ .../overWriteResolveClass.java | 114 +++ .../overWriteWriteReplace.java | 99 ++ .../overWriteSer/overWriteAnnotateClass.java | 108 +++ .../overWriteSer/overWriteReadResolve.java | 86 ++ .../overWriteSer/overWriteResolveClass.java | 102 +++ .../overWriteSer/overWriteWriteObject.java | 81 ++ .../overWriteSer/overWriteWriteReplace.java | 85 ++ .../io/FastSerializer/packageAccess/A.java | 20 + .../io/FastSerializer/packageAccess/B.java | 14 + .../io/FastSerializer/packageAccess/C.java | 20 + .../io/FastSerializer/packageAccess/D.java | 11 + .../packageAccess/TestDescription.java | 24 + .../FastSerializer/parents/EvolvedClass.java | 66 ++ .../partialClassDesc/TestDescription.java | 22 + .../primitiveClasses/TestDescription.java | 20 + .../protocolVersion1/arrayVersion1.java | 68 ++ .../protocolVersion1/enumVersion.java | 69 ++ .../protocolVersion1/externVersion1.java | 96 ++ .../protocolVersion1/serVersion1.java | 66 ++ .../protocolVersion1/stringVersion1.java | 44 + .../FastSerializer/proxy/TestDescription.java | 20 + .../proxy/replace/TestDescription.java | 20 + .../readPastObject/TestDescription.java | 21 + .../TestDescription.java | 22 + .../replaceStringArray/TestDescription.java | 20 + .../replaceWithNull/TestDescription.java | 20 + .../resolveClass/TestDescription.java | 21 + .../resolveClass/consTest/Boot.java | 15 + .../resolveClass/consTest/ConsTest.java | 36 + .../resolveClass/consTest/SetupJar.java | 13 + .../DeserializeButtonTest.java | 50 ++ .../resolveClass/deserializeButton/Foo.java | 38 + .../ResolveClassException.java | 75 ++ .../TestDescription.java | 21 + .../resolveProxyClass/TestDescription.java | 22 + .../sanityCheck/TestDescription.java | 21 + .../serialFilter/SerialFilterTest.java | 848 ++++++++++++++++++ .../serialFilter/TestDescription.java | 84 ++ .../serialFilter/java.security-extra1 | 4 + .../serialFilter/security.policy | 13 + .../security.policy.without.globalFilter | 9 + .../serialver/classpath/ClasspathTest.java | 54 ++ .../serialver/nested/NestedTest.java | 58 ++ .../skipToEndOfBlockData/TestDescription.java | 23 + .../TestDescription.java | 29 + .../TestDescription.java | 29 + .../io/FastSerializer/subclass/Allow.policy | 9 + .../subclass/TestDescription.java | 38 + .../subclassGC/SubclassOfOOS.java | 13 + .../subclassGC/TestDescription.java | 26 + .../FastSerializer/subclassGC/security.policy | 8 + .../FastSerializer/superclassDataLoss/A.java | 13 + .../FastSerializer/superclassDataLoss/B.java | 19 + .../superclassDataLoss/TestDescription.java | 24 + .../TestDescription.java | 23 + .../typeSafeEnum/TestDescription.java | 22 + .../typeStringBackRef/TypeStringBackRef.java | 37 + .../serialPersistentFieldsExt.java | 94 ++ .../serialPersistentFieldsSer.java | 84 ++ .../unSerializable/staticExternal.java | 94 ++ .../unSerializable/staticSerializ.java | 82 ++ .../unSerializable/transientExternal.java | 99 ++ .../unSerializable/transientSerializ.java | 87 ++ .../TestDescription.java | 21 + .../unnamedPackageSwitch/TestDescription.java | 25 + .../unnamedPackageSwitch/pkg/A.java | 14 + .../TestDescription.java | 24 + .../unresolvedClassDesc/Foo.java | 11 + .../unresolvedClassDesc/Read.java | 32 + .../unresolvedClassDesc/TestDescription.java | 30 + .../unresolvedClassDesc/Write.java | 33 + .../unshared/TestDescription.java | 27 + .../userRWObjError/TestDescription.java | 21 + .../FastSerializer/util/CleanActualClass.java | 44 + .../validate/TestDescription.java | 22 + .../TestDescription.java | 20 + .../writeObjectMemory/TestDescription.java | 21 + .../writeReplace/TestDescription.java | 19 + .../wrongReturnTypes/TestDescription.java | 28 + 183 files changed, 8436 insertions(+) create mode 100644 test/jdk/java/io/FastSerializer/ClassCastExceptionDetail/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/InvalidClassException/noargctor/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/NPEProvoker/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/NoClassDefFoundErrorTrap/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/PutField/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/arraySuidConflict/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/auditStreamSubclass/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/available/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/backRefCNFException/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/badSerialPersistentField/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/badSerialVersionUID/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/badSubstByReplace/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/checkModifiers/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/class/NonSerialA_1/A.java create mode 100644 test/jdk/java/io/FastSerializer/class/NonSerialA_2/A.java create mode 100644 test/jdk/java/io/FastSerializer/class/SerialA_1/A.java create mode 100644 test/jdk/java/io/FastSerializer/class/SerialA_2/A.java create mode 100644 test/jdk/java/io/FastSerializer/class/SerialA_3/A.java create mode 100644 test/jdk/java/io/FastSerializer/class/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/class/TestEntry.java create mode 100644 test/jdk/java/io/FastSerializer/classDescGetField/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/classDescHooks/Foo.ser create mode 100644 test/jdk/java/io/FastSerializer/classDescHooks/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/classLoader/classLoaderExtern.java create mode 100644 test/jdk/java/io/FastSerializer/classLoader/classLoaderSer.java create mode 100644 test/jdk/java/io/FastSerializer/clearHandleTable/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/cloneArray/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/concurrentClassDescLookup/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/corruptedUTFConsumption/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/defaultDataEnd/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/defaultReadObjectCNFException/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/diffExtern/Foo.ser create mode 100644 test/jdk/java/io/FastSerializer/diffExtern/Foo2.ser create mode 100644 test/jdk/java/io/FastSerializer/diffExtern/addField.java create mode 100644 test/jdk/java/io/FastSerializer/diffExtern/addclass.java create mode 100644 test/jdk/java/io/FastSerializer/diffExtern/changeModifier.java create mode 100644 test/jdk/java/io/FastSerializer/diffExtern/deletField.java create mode 100644 test/jdk/java/io/FastSerializer/diffExtern/removeStatic.java create mode 100644 test/jdk/java/io/FastSerializer/diffExtern/staticField.java create mode 100644 test/jdk/java/io/FastSerializer/diffSer/Foo.ser create mode 100644 test/jdk/java/io/FastSerializer/diffSer/Foo4.ser create mode 100644 test/jdk/java/io/FastSerializer/diffSer/addField.java create mode 100644 test/jdk/java/io/FastSerializer/diffSer/addclass.java create mode 100644 test/jdk/java/io/FastSerializer/diffSer/changeModifier.java create mode 100644 test/jdk/java/io/FastSerializer/diffSer/deletField.java create mode 100644 test/jdk/java/io/FastSerializer/diffSer/removeStatic.java create mode 100644 test/jdk/java/io/FastSerializer/diffSer/staticField.java create mode 100644 test/jdk/java/io/FastSerializer/duplicateSerialFields/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/dynamicProxy/dynamicExtern.java create mode 100644 test/jdk/java/io/FastSerializer/dynamicProxy/dynamicSer.java create mode 100644 test/jdk/java/io/FastSerializer/enum/array/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/enum/basic/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/enum/classObject/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/enum/constantSubclasses/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/enum/ignoreSerializationFields/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/enum/ignoreSerializationMethods/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/enum/mismatchedTypecode/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/enum/missingConstant/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/enum/unshared/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/evolution/AddedSuperClass/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/evolution/RenamePackage/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/evolution/RenamePackage/extension/ExtendedObjectInputStream.java create mode 100644 test/jdk/java/io/FastSerializer/evolution/RenamePackage/install/SerialDriver.java create mode 100644 test/jdk/java/io/FastSerializer/evolution/RenamePackage/test/SerialDriver.java create mode 100644 test/jdk/java/io/FastSerializer/expectedStackTrace/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/explicitCNFException/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/failureAtomicity/Bar.template create mode 100644 test/jdk/java/io/FastSerializer/failureAtomicity/Foo.template create mode 100644 test/jdk/java/io/FastSerializer/failureAtomicity/SerialRef.java create mode 100644 test/jdk/java/io/FastSerializer/failureAtomicity/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/finalFields/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/getSuidClinitError/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/illegalHandle/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/illegalHandle/negativeHandle.ser create mode 100644 test/jdk/java/io/FastSerializer/illegalHandle/tooHighHandle.ser create mode 100644 test/jdk/java/io/FastSerializer/inactiveRegistration/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/innerClass/innerExtern.java create mode 100644 test/jdk/java/io/FastSerializer/innerClass/innerSerial.java create mode 100644 test/jdk/java/io/FastSerializer/logging.properties create mode 100644 test/jdk/java/io/FastSerializer/longString/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/longString/mesg.ser create mode 100644 test/jdk/java/io/FastSerializer/lookupAnyInvocation/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/lookupInterfaceDesc/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/maskSyntheticModifier/Foo.class create mode 100644 test/jdk/java/io/FastSerializer/maskSyntheticModifier/Foo.java create mode 100644 test/jdk/java/io/FastSerializer/maskSyntheticModifier/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/misplacedArrayClassDesc/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/modifyStaticFields/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/nestedReplace/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/noSuchFieldClarification/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/nonserializable/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/normalExter/normalClassExternalize.java create mode 100644 test/jdk/java/io/FastSerializer/normalSer/ArraySerialize.java create mode 100644 test/jdk/java/io/FastSerializer/normalSer/EnumSerialize.java create mode 100644 test/jdk/java/io/FastSerializer/normalSer/StringSerialize.java create mode 100644 test/jdk/java/io/FastSerializer/normalSer/normalClassSerialize.java create mode 100644 test/jdk/java/io/FastSerializer/notAvailable/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/nullArgExceptionOrder/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/nullStream/nullExtern.java create mode 100644 test/jdk/java/io/FastSerializer/nullStream/nullSerial.java create mode 100644 test/jdk/java/io/FastSerializer/oldTests/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/optionalDataEnd/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/overWriteExtern/overWriteAnnotateClass.java create mode 100644 test/jdk/java/io/FastSerializer/overWriteExtern/overWriteReadResolve.java create mode 100644 test/jdk/java/io/FastSerializer/overWriteExtern/overWriteResolveClass.java create mode 100644 test/jdk/java/io/FastSerializer/overWriteExtern/overWriteWriteReplace.java create mode 100644 test/jdk/java/io/FastSerializer/overWriteSer/overWriteAnnotateClass.java create mode 100644 test/jdk/java/io/FastSerializer/overWriteSer/overWriteReadResolve.java create mode 100644 test/jdk/java/io/FastSerializer/overWriteSer/overWriteResolveClass.java create mode 100644 test/jdk/java/io/FastSerializer/overWriteSer/overWriteWriteObject.java create mode 100644 test/jdk/java/io/FastSerializer/overWriteSer/overWriteWriteReplace.java create mode 100644 test/jdk/java/io/FastSerializer/packageAccess/A.java create mode 100644 test/jdk/java/io/FastSerializer/packageAccess/B.java create mode 100644 test/jdk/java/io/FastSerializer/packageAccess/C.java create mode 100644 test/jdk/java/io/FastSerializer/packageAccess/D.java create mode 100644 test/jdk/java/io/FastSerializer/packageAccess/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/parents/EvolvedClass.java create mode 100644 test/jdk/java/io/FastSerializer/partialClassDesc/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/primitiveClasses/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/protocolVersion1/arrayVersion1.java create mode 100644 test/jdk/java/io/FastSerializer/protocolVersion1/enumVersion.java create mode 100644 test/jdk/java/io/FastSerializer/protocolVersion1/externVersion1.java create mode 100644 test/jdk/java/io/FastSerializer/protocolVersion1/serVersion1.java create mode 100644 test/jdk/java/io/FastSerializer/protocolVersion1/stringVersion1.java create mode 100644 test/jdk/java/io/FastSerializer/proxy/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/proxy/replace/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/readPastObject/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/recursiveClassDescLookup/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/replaceStringArray/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/replaceWithNull/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/resolveClass/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/resolveClass/consTest/Boot.java create mode 100644 test/jdk/java/io/FastSerializer/resolveClass/consTest/ConsTest.java create mode 100644 test/jdk/java/io/FastSerializer/resolveClass/consTest/SetupJar.java create mode 100644 test/jdk/java/io/FastSerializer/resolveClass/deserializeButton/DeserializeButtonTest.java create mode 100644 test/jdk/java/io/FastSerializer/resolveClass/deserializeButton/Foo.java create mode 100644 test/jdk/java/io/FastSerializer/resolveClassException/ResolveClassException.java create mode 100644 test/jdk/java/io/FastSerializer/resolveClassException/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/resolveProxyClass/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/sanityCheck/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/serialFilter/SerialFilterTest.java create mode 100644 test/jdk/java/io/FastSerializer/serialFilter/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/serialFilter/java.security-extra1 create mode 100644 test/jdk/java/io/FastSerializer/serialFilter/security.policy create mode 100644 test/jdk/java/io/FastSerializer/serialFilter/security.policy.without.globalFilter create mode 100644 test/jdk/java/io/FastSerializer/serialver/classpath/ClasspathTest.java create mode 100644 test/jdk/java/io/FastSerializer/serialver/nested/NestedTest.java create mode 100644 test/jdk/java/io/FastSerializer/skipToEndOfBlockData/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/skippedObjCNFException/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/stopCustomDeserialization/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/subclass/Allow.policy create mode 100644 test/jdk/java/io/FastSerializer/subclass/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/subclassGC/SubclassOfOOS.java create mode 100644 test/jdk/java/io/FastSerializer/subclassGC/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/subclassGC/security.policy create mode 100644 test/jdk/java/io/FastSerializer/superclassDataLoss/A.java create mode 100644 test/jdk/java/io/FastSerializer/superclassDataLoss/B.java create mode 100644 test/jdk/java/io/FastSerializer/superclassDataLoss/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/survivePrematureClose/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/typeSafeEnum/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/typeStringBackRef/TypeStringBackRef.java create mode 100644 test/jdk/java/io/FastSerializer/unSerializable/serialPersistentFieldsExt.java create mode 100644 test/jdk/java/io/FastSerializer/unSerializable/serialPersistentFieldsSer.java create mode 100644 test/jdk/java/io/FastSerializer/unSerializable/staticExternal.java create mode 100644 test/jdk/java/io/FastSerializer/unSerializable/staticSerializ.java create mode 100644 test/jdk/java/io/FastSerializer/unSerializable/transientExternal.java create mode 100644 test/jdk/java/io/FastSerializer/unSerializable/transientSerializ.java create mode 100644 test/jdk/java/io/FastSerializer/underlyingOutputStreamException/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/unnamedPackageSwitch/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/unnamedPackageSwitch/pkg/A.java create mode 100644 test/jdk/java/io/FastSerializer/unresolvableObjectStreamClass/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/unresolvedClassDesc/Foo.java create mode 100644 test/jdk/java/io/FastSerializer/unresolvedClassDesc/Read.java create mode 100644 test/jdk/java/io/FastSerializer/unresolvedClassDesc/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/unresolvedClassDesc/Write.java create mode 100644 test/jdk/java/io/FastSerializer/unshared/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/userRWObjError/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/util/CleanActualClass.java create mode 100644 test/jdk/java/io/FastSerializer/validate/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/verifyDynamicObjHandleTable/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/writeObjectMemory/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/writeReplace/TestDescription.java create mode 100644 test/jdk/java/io/FastSerializer/wrongReturnTypes/TestDescription.java diff --git a/test/jdk/java/io/FastSerializer/ClassCastExceptionDetail/TestDescription.java b/test/jdk/java/io/FastSerializer/ClassCastExceptionDetail/TestDescription.java new file mode 100644 index 000000000..d106d2667 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/ClassCastExceptionDetail/TestDescription.java @@ -0,0 +1,30 @@ +/* +*- @TestCaseID:FastSerializer/ClassCastExceptionDetail +*- @TestCaseName:ClassCastExceptionDetail +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4511532 + * @summary Verify that the message string of a ClassCastException thrown by + * ObjectInputStream when attempting to assign a value to a field of + * an incompatible type contains the names of the value's class, the + * field's declaring class, the field's type, and the field itself. + * + * @library /test/jdk/java/io/Serializable/ClassCastExceptionDetail + * @clean Write Read Foo Gub + * @build Write + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Write + * @clean Write Read Foo Gub + * @build Read + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Read + * + */ diff --git a/test/jdk/java/io/FastSerializer/InvalidClassException/noargctor/TestDescription.java b/test/jdk/java/io/FastSerializer/InvalidClassException/noargctor/TestDescription.java new file mode 100644 index 000000000..d73f1cea2 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/InvalidClassException/noargctor/TestDescription.java @@ -0,0 +1,36 @@ +/* +*- @TestCaseID:FastSerializer/noargctor +*- @TestCaseName:noargctor +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* + * @test + * @bug 4093279 + * @summary Validate accessibility checking to NonSerializable superclass constuctor. + * @library /test/jdk/java/io/Serializable/InvalidClassException/noargctor + * @build NonSerialize.PrivateCtor + * NonSerialize.ProtectedCtor + * NonSerialize.PackageCtor + * NonSerialize.PublicCtor + * @build Serialize.SubclassAcrossPackage + * Serialize.SamePackageCtor + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Test + */ + +/* @test + * @bug 4093279 + * @summary Raise InvalidClassException if 1st NonSerializable superclass' no-arg constructor is not accessible. This test verifies default package access. + * @library /test/jdk/java/io/Serializable/InvalidClassException/noargctor + * @build DefaultPackage + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer DefaultPackage + */ + diff --git a/test/jdk/java/io/FastSerializer/NPEProvoker/TestDescription.java b/test/jdk/java/io/FastSerializer/NPEProvoker/TestDescription.java new file mode 100644 index 000000000..e535988dc --- /dev/null +++ b/test/jdk/java/io/FastSerializer/NPEProvoker/TestDescription.java @@ -0,0 +1,25 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/NPEProvoker +*- @TestCaseName:jdk17_NPEProvoker +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 6541870 + * @summary this test checks that ObjectInputStream throws an IOException + * instead of a NullPointerException when deserializing an ArrayList + * of Externalizables if there is an IOException while deserializing + * one of these Externalizables. + * + * @author Andrey Ozerov + * @library /test/jdk/java/io/Serializable/NPEProvoker/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer NPEProvoker + */ diff --git a/test/jdk/java/io/FastSerializer/NoClassDefFoundErrorTrap/TestDescription.java b/test/jdk/java/io/FastSerializer/NoClassDefFoundErrorTrap/TestDescription.java new file mode 100644 index 000000000..fc0be1fde --- /dev/null +++ b/test/jdk/java/io/FastSerializer/NoClassDefFoundErrorTrap/TestDescription.java @@ -0,0 +1,26 @@ +/* +*- @TestCaseID:FastSerializer/NoClassDefFoundErrorTrap +*- @TestCaseName:NoClassDefFoundErrorTrap +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4205440 + * @summary When ObjectInputStream.inputClassDescriptor calls its protected + * resolveClass, if a NoClassDefFoundError is thrown, that Error should be + * propagated to the caller, instead of being trapped and transformed into + * a ClassNotFoundException for the class being resolved. + * @author Peter Jones + * + * @library /test/jdk/java/io/Serializable/NoClassDefFoundErrorTrap/ + * @build NoClassDefFoundErrorTrap + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer NoClassDefFoundErrorTrap + */ diff --git a/test/jdk/java/io/FastSerializer/PutField/TestDescription.java b/test/jdk/java/io/FastSerializer/PutField/TestDescription.java new file mode 100644 index 000000000..8810243c1 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/PutField/TestDescription.java @@ -0,0 +1,42 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/PutField +*- @TestCaseName:PutField +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4453723 + * + * @library /test/jdk/java/io/Serializable/PutField/ + * @clean Write2 Read2 Foo + * @build Write2 + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Write2 + * @clean Write2 Read2 Foo + * @build Read2 + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Read2 + * + * @summary Verify that ObjectOutputStream.PutField.write() works for objects + * that do not define primitive serializable fields. + */ + +/* @test + * + * @library /test/jdk/java/io/Serializable/PutField/ + * @clean Write Read Foo + * @build Write + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Write + * @clean Write Read Foo + * @build Read + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Read + * + * @summary Verify that the ObjectOutputStream.PutField API works as + * advertised. + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/arraySuidConflict/TestDescription.java b/test/jdk/java/io/FastSerializer/arraySuidConflict/TestDescription.java new file mode 100644 index 000000000..66fbd38f6 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/arraySuidConflict/TestDescription.java @@ -0,0 +1,27 @@ +/* +*- @TestCaseID:FastSerializer/arraySuidConflict +*- @TestCaseName:arraySuidConflict +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4490677 + * @summary Verify that array serialVersionUID conflicts caused by changes in + * package scope do not cause deserialization to fail. + * + * @library /test/jdk/java/io/Serializable/arraySuidConflict + * @clean Write Read Foo + * @build Write Foo + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Write + * @clean Write Read Foo + * @build Read + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Read + */ diff --git a/test/jdk/java/io/FastSerializer/auditStreamSubclass/TestDescription.java b/test/jdk/java/io/FastSerializer/auditStreamSubclass/TestDescription.java new file mode 100644 index 000000000..a8f63d41c --- /dev/null +++ b/test/jdk/java/io/FastSerializer/auditStreamSubclass/TestDescription.java @@ -0,0 +1,25 @@ +/* +*- @TestCaseID:FastSerializer/auditStreamSubclass +*- @TestCaseName:auditStreamSubclass +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4311940 + * @summary Verify that unauthorized ObjectOutputStream and ObjectInputStream + * cannot be constructed if they override security-sensitive non-final + * methods. + * + * @library /test/jdk/java/io/Serializable/auditStreamSubclass + * @build AuditStreamSubclass + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer AuditStreamSubclass + */ + diff --git a/test/jdk/java/io/FastSerializer/available/TestDescription.java b/test/jdk/java/io/FastSerializer/available/TestDescription.java new file mode 100644 index 000000000..4c807632b --- /dev/null +++ b/test/jdk/java/io/FastSerializer/available/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:FastSerializer/available +*- @TestCaseName:available +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ +/* @test + * @bug 4400571 + * @summary Verify that ObjectInputStream.available() functions properly when + * called at the beginning of a data block, and that it does not + * attempt any read operations that may potentially block. + * @library /test/jdk/java/io/Serializable/available + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Available + */ + diff --git a/test/jdk/java/io/FastSerializer/backRefCNFException/TestDescription.java b/test/jdk/java/io/FastSerializer/backRefCNFException/TestDescription.java new file mode 100644 index 000000000..52e31b946 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/backRefCNFException/TestDescription.java @@ -0,0 +1,28 @@ +/* +*- @TestCaseID:FastSerializer/backRefCNFException +*- @TestCaseName:backRefCNFException +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4312433 + * @summary Verify that reading a back reference to a previously skipped value + * whose class is not available will throw a ClassNotFoundException + * @library /test/jdk/java/io/Serializable/backRefCNFException + * /test/jdk/java/io/FastSerializer/util + * @run driver CleanActualClass Write.class Read.class A.class B.class + * @build Write + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Write + * @run driver CleanActualClass Write.class Read.class A.class B.class + * @build Read + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Read + * + */ diff --git a/test/jdk/java/io/FastSerializer/badSerialPersistentField/TestDescription.java b/test/jdk/java/io/FastSerializer/badSerialPersistentField/TestDescription.java new file mode 100644 index 000000000..8e8164a01 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/badSerialPersistentField/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:FastSerializer/badSerialPersistentField +*- @TestCaseName:badSerialPersistentField +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4387368 + * @summary Verify that object whose class declared a serial persistent field + * that does not match any actual field cannot be serialized via + * default serialization. + * @library /test/jdk/java/io/Serializable/badSerialPersistentField + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer BadSerialPersistentField + */ diff --git a/test/jdk/java/io/FastSerializer/badSerialVersionUID/TestDescription.java b/test/jdk/java/io/FastSerializer/badSerialVersionUID/TestDescription.java new file mode 100644 index 000000000..4e856e889 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/badSerialVersionUID/TestDescription.java @@ -0,0 +1,23 @@ +/* +*- @TestCaseID:FastSerializer/badSerialVersionUID +*- @TestCaseName:badSerialVersionUID +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4431318 + * @summary Verify that when serialVersionUID is declared with a type other + * than long, values that can be promoted to long will be used, and + * those that can't be will be ignored (but will not result in + * unchecked exceptions). + * @library /test/jdk/java/io/Serializable/badSerialVersionUID + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer BadSerialVersionUID + */ diff --git a/test/jdk/java/io/FastSerializer/badSubstByReplace/TestDescription.java b/test/jdk/java/io/FastSerializer/badSubstByReplace/TestDescription.java new file mode 100644 index 000000000..348c8c4d3 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/badSubstByReplace/TestDescription.java @@ -0,0 +1,21 @@ +/* +*- @TestCaseID:FastSerializer/badSubstByReplace +*- @TestCaseName:badSubstByReplace +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @summary Verify that ClassCastException is thrown when deserializing + * an object and one of its object fields is incompatibly replaced + * by either replaceObject/resolveObject. + * @library /test/jdk/java/io/Serializable/badSubstByReplace + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer BadSubstByReplace + */ diff --git a/test/jdk/java/io/FastSerializer/checkModifiers/TestDescription.java b/test/jdk/java/io/FastSerializer/checkModifiers/TestDescription.java new file mode 100644 index 000000000..118920afb --- /dev/null +++ b/test/jdk/java/io/FastSerializer/checkModifiers/TestDescription.java @@ -0,0 +1,27 @@ +/* +*- @TestCaseID:FastSerializer/checkModifiers +*- @TestCaseName:checkModifiers +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4214888 + * @summary Make sure that serialpersistentFields data member is used to + * represent tyhe serializable fields only if it has the modfiers + * static, final, private and the type is ObjectStreamField. + * No need to check for static, as ObjectStreamField class is not + * serializable. + * @library /test/jdk/java/io/Serializable/checkModifiers + * @clean CheckModifiers TestClass1 TestClass2 + * @build CheckModifiers + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer CheckModifiers + * + */ diff --git a/test/jdk/java/io/FastSerializer/class/NonSerialA_1/A.java b/test/jdk/java/io/FastSerializer/class/NonSerialA_1/A.java new file mode 100644 index 000000000..10baeb2c1 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/class/NonSerialA_1/A.java @@ -0,0 +1,5 @@ + + +public class A { + int field1; +}; diff --git a/test/jdk/java/io/FastSerializer/class/NonSerialA_2/A.java b/test/jdk/java/io/FastSerializer/class/NonSerialA_2/A.java new file mode 100644 index 000000000..e28f11230 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/class/NonSerialA_2/A.java @@ -0,0 +1,6 @@ + + +public class A { + int field1; + int field2; +}; diff --git a/test/jdk/java/io/FastSerializer/class/SerialA_1/A.java b/test/jdk/java/io/FastSerializer/class/SerialA_1/A.java new file mode 100644 index 000000000..89ae1e831 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/class/SerialA_1/A.java @@ -0,0 +1,7 @@ + + +import java.io.Serializable; + +public class A implements Serializable { + int field1; +}; diff --git a/test/jdk/java/io/FastSerializer/class/SerialA_2/A.java b/test/jdk/java/io/FastSerializer/class/SerialA_2/A.java new file mode 100644 index 000000000..d3a6aa869 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/class/SerialA_2/A.java @@ -0,0 +1,10 @@ + + +import java.io.Serializable; + +public class A implements Serializable { + static final long serialVersionUID = 746945609796141988L; + + int field1; + int field2; +}; diff --git a/test/jdk/java/io/FastSerializer/class/SerialA_3/A.java b/test/jdk/java/io/FastSerializer/class/SerialA_3/A.java new file mode 100644 index 000000000..ddeeea6e4 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/class/SerialA_3/A.java @@ -0,0 +1,10 @@ + + +import java.io.Serializable; + +/* THis class is purposely not compatible with previous versions of class.*/ +public class A implements Serializable { + int field1; + int field2; + int field3; +}; diff --git a/test/jdk/java/io/FastSerializer/class/TestDescription.java b/test/jdk/java/io/FastSerializer/class/TestDescription.java new file mode 100644 index 000000000..c3a2d2f51 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/class/TestDescription.java @@ -0,0 +1,28 @@ +/* +*- @TestCaseID:FastSerializer/class +*- @TestCaseName:class +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* + * @test + * @bug 4075221 + * @library /test/lib /test/jdk/java/io/Serializable/class + * @build jdk.test.lib.compiler.CompilerUtils + * jdk.test.lib.Utils + * jdk.test.lib.Asserts + * jdk.test.lib.JDKToolFinder + * jdk.test.lib.JDKToolLauncher + * jdk.test.lib.Platform + * jdk.test.lib.process.* + * @run testng/othervm/timeout=300 -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer NonSerializableTest + * @summary Enable serialize of nonSerializable Class descriptor. + */ diff --git a/test/jdk/java/io/FastSerializer/class/TestEntry.java b/test/jdk/java/io/FastSerializer/class/TestEntry.java new file mode 100644 index 000000000..6a588fb11 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/class/TestEntry.java @@ -0,0 +1,77 @@ +/* +*- @TestCaseID:FastSerializer/TestEntry +*- @TestCaseName:TestEntry +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ +/* + * @bug 4075221 + * @summary Enable serialize of nonSerializable Class descriptor. + */ + +import java.io.EOFException; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileInputStream; +import java.io.InvalidClassException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamClass; + +class TestEntry { + public static void main(String args[]) throws Exception { + File f = new File("tmp.ser"); + if (args[0].compareTo("-s") == 0) { + FileOutputStream of = new FileOutputStream(f); + ObjectOutputStream oos = new ObjectOutputStream(of); + Class cl = Class.forName(args[1]); + oos.writeObject(cl); + if (ObjectStreamClass.lookup(cl) != null) + oos.writeObject(cl.newInstance()); + oos.close(); + System.out.println("Serialized Class " + cl.getName()); + } else if (args[0].compareTo("-de") == 0) { + FileInputStream inf = new FileInputStream(f); + ObjectInputStream ois = new ObjectInputStream(inf); + Class cl = null; + try { + cl = (Class)ois.readObject(); + throw new Error("Expected InvalidClassException to be thrown"); + } catch (InvalidClassException e) { + System.out.println("Caught expected exception DeSerializing class " + e.getMessage()); + } + ois.close(); + } else if (args[0].compareTo("-doe") == 0) { + FileInputStream inf = new FileInputStream(f); + ObjectInputStream ois = new ObjectInputStream(inf); + Class cl = null; + cl = (Class)ois.readObject(); + try { + ois.readObject(); + throw new Error("Expected InvalidClassException to be thrown"); + } catch (InvalidClassException e) { + System.out.println("Caught expected exception DeSerializing class " + e.getMessage()); + } + ois.close(); + } else if (args[0].compareTo("-d") == 0) { + FileInputStream inf = new FileInputStream(f); + ObjectInputStream ois = new ObjectInputStream(inf); + Class cl = (Class)ois.readObject(); + try { + ois.readObject(); + } catch (EOFException e) { + } + ois.close(); + System.out.println("DeSerialized Class " + cl.getName()); + } else { + throw new RuntimeException("Unrecognized argument"); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/classDescGetField/TestDescription.java b/test/jdk/java/io/FastSerializer/classDescGetField/TestDescription.java new file mode 100644 index 000000000..511b3bcb0 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/classDescGetField/TestDescription.java @@ -0,0 +1,25 @@ +/* +*- @TestCaseID:FastSerializer/classDescGetField +*- @TestCaseName:classDescGetField +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4180735 + * @summary Make sure that getField() of ObjectStreamClass works correctly for + * object types. + * + * @library /test/jdk/java/io/Serializable/classDescGetField + * @clean Foo GetField + * @build GetField + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer GetField + * + */ diff --git a/test/jdk/java/io/FastSerializer/classDescHooks/Foo.ser b/test/jdk/java/io/FastSerializer/classDescHooks/Foo.ser new file mode 100644 index 0000000000000000000000000000000000000000..96be5f23047ecc23dcf67bc93a4a6794cfe11eba GIT binary patch literal 271 zcmZ4UmVvdnh=JKHKc4{t7?~KDeHa)sOBjTGvJ%S@^>Y&Q()B&_N>bBPi>!e%IVB7N zNHRY8dFdeG;t~cyB;nwU{Gt-;iUOeFf*@n`K*s1njS+gZV9EE!b_*s3Mo$LTvc#Oy z)QTbo0faig(%hufqP8_tWx1z3=w@PIs3-usjtOWOA3_n>=I$pG&h#ta2b$ysGpUfF gj)4v88)l#ueuNgVt1^7eg-sG}1p)O0qv~M<00bFPK>z>% literal 0 HcmV?d00001 diff --git a/test/jdk/java/io/FastSerializer/classDescHooks/TestDescription.java b/test/jdk/java/io/FastSerializer/classDescHooks/TestDescription.java new file mode 100644 index 000000000..805ff4c1b --- /dev/null +++ b/test/jdk/java/io/FastSerializer/classDescHooks/TestDescription.java @@ -0,0 +1,51 @@ +/* +*- @TestCaseID:FastSerializer/classDescHooks +*- @TestCaseName:classDescHooks +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4227189 + * @summary Ensure that class descriptor read, write hooks exist, are backwards + * compatible, and work as advertised. + * @library /test/jdk/java/io/Serializable/classDescHooks + * @ignore + * @build ClassDescHooks + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer ClassDescHooks + */ + +/* @test + * @bug 4931314 + * @summary Verify that a ClassNotFoundException thrown by the + * readClassDescriptor method is reflected to the caller as an + * InvalidClassException with the ClassNotFoundException as its cause. + * @library /test/jdk/java/io/Serializable/classDescHooks + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer CNFException + */ + +/* @test + * @bug 4461737 + * @summary Verify that serialization functions properly for externalizable + * classes if ObjectInputStream.readClassDescriptor() returns a local + * class descriptor. + * @library /test/jdk/java/io/Serializable/classDescHooks + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer ExternLoopback + */ + +/* @test + * @bug 4461299 + * @summary Verify that serialization functions properly if + * ObjectInputStream.readClassDescriptor() returns a local class + * descriptor for which the serialVersionUID has not yet been + * calculated. + * @library /test/jdk/java/io/Serializable/classDescHooks + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Loopback + */ diff --git a/test/jdk/java/io/FastSerializer/classLoader/classLoaderExtern.java b/test/jdk/java/io/FastSerializer/classLoader/classLoaderExtern.java new file mode 100644 index 000000000..95a5ddc53 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/classLoader/classLoaderExtern.java @@ -0,0 +1,137 @@ +/* +*- @TestCaseID:FastSerializer/classLoaderExtern +*- @TestCaseName:classLoaderExtern +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test change field to static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true classLoaderExtern +*/ + + +import java.io.*; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; + +class Foo implements Externalizable { + int i ; + String s ; + public Foo(){} + Foo (int i, String s) { + this.i = i; + this.s = s; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s) ); + } +} + +class MyObjectInputStream extends ObjectInputStream { + protected ClassLoader classLoader = this.getClass().getClassLoader(); + public MyObjectInputStream(InputStream in) throws IOException { + super(in); + } + + public MyObjectInputStream(InputStream in, ClassLoader cl) throws IOException{ + super(in); + this.classLoader = cl; + } + @Override + protected ClassresolveClass(ObjectStreamClass desc)throws IOException,ClassNotFoundException { + String name = desc.getName(); + try { + return Class.forName(name,false,this.classLoader); + }catch(ClassNotFoundException Ex) { + return super.resolveClass(desc); + } + } +} + +class MyClassLoader extends ClassLoader { + protected Class findClass(String name) throws ClassNotFoundException { + Class clazz = null; + String classFilename = name + ".class"; + File classFile = new File(classFilename); + if (classFile.exists()) { + try (FileChannel fileChannel = new FileInputStream(classFile) + .getChannel();) { + MappedByteBuffer mappedByteBuffer = fileChannel + .map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size()); + byte[] b = mappedByteBuffer.array(); + clazz = defineClass(name, b, 0, b.length); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (clazz == null) { + throw new ClassNotFoundException(name); + } + return clazz; + } +} + +public class classLoaderExtern { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + MyClassLoader myClassLoader = new MyClassLoader(); + MyObjectInputStream oin2 = new MyObjectInputStream(new FileInputStream("Foo.ser"), myClassLoader); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/classLoader/classLoaderSer.java b/test/jdk/java/io/FastSerializer/classLoader/classLoaderSer.java new file mode 100644 index 000000000..a3eef86fe --- /dev/null +++ b/test/jdk/java/io/FastSerializer/classLoader/classLoaderSer.java @@ -0,0 +1,124 @@ +/* +*- @TestCaseID:FastSerializer/classLoaderSer +*- @TestCaseName:classLoaderSer +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test change field to static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true classLoaderSer +*/ + + +import java.io.*; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; + +class Foo implements Serializable { + Foo (int i, String s) { + this.i = i; + this.s = s; + } + int i; + String s ; + + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s)); + } +} +class MyObjectInputStream extends ObjectInputStream { + protected ClassLoader classLoader = this.getClass().getClassLoader(); + public MyObjectInputStream(InputStream in) throws IOException { + super(in); + } + + public MyObjectInputStream(InputStream in, ClassLoader cl) throws IOException{ + super(in); + this.classLoader = cl; + } + @Override + protected ClassresolveClass(ObjectStreamClass desc)throws IOException,ClassNotFoundException { + String name = desc.getName(); + try { + return Class.forName(name,false,this.classLoader); + }catch(ClassNotFoundException Ex) { + return super.resolveClass(desc); + } + } +} + +class MyClassLoader extends ClassLoader { + protected Class findClass(String name) throws ClassNotFoundException { + Class clazz = null; + String classFilename = name + ".class"; + File classFile = new File(classFilename); + if (classFile.exists()) { + try (FileChannel fileChannel = new FileInputStream(classFile) + .getChannel();) { + MappedByteBuffer mappedByteBuffer = fileChannel + .map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size()); + byte[] b = mappedByteBuffer.array(); + clazz = defineClass(name, b, 0, b.length); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (clazz == null) { + throw new ClassNotFoundException(name); + } + return clazz; + } +} + +public class classLoaderSer { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + MyClassLoader myClassLoader = new MyClassLoader(); + MyObjectInputStream oin2 = new MyObjectInputStream(new FileInputStream("Foo.ser"), myClassLoader); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/clearHandleTable/TestDescription.java b/test/jdk/java/io/FastSerializer/clearHandleTable/TestDescription.java new file mode 100644 index 000000000..5b82ab10b --- /dev/null +++ b/test/jdk/java/io/FastSerializer/clearHandleTable/TestDescription.java @@ -0,0 +1,21 @@ +/* +*- @TestCaseID:FastSerializer/ClearHandleTable +*- @TestCaseName:ClearHandleTable +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4332184 + * @summary Ensure that ObjectOutputStream properly releases strong references + * to written objects when reset() is called. + * @library /test/jdk/java/io/Serializable/clearHandleTable + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer ClearHandleTable + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/cloneArray/TestDescription.java b/test/jdk/java/io/FastSerializer/cloneArray/TestDescription.java new file mode 100644 index 000000000..cee388765 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/cloneArray/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:FastSerializer/CloneArray +*- @TestCaseName:CloneArray +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + + +/* @test + * @bug 6990094 + * @summary Verify ObjectInputStream.cloneArray works on many kinds of arrays + * @author Stuart Marks, Joseph D. Darcy + * @library /test/jdk/java/io/Serializable/cloneArray + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer CloneArray + */ diff --git a/test/jdk/java/io/FastSerializer/concurrentClassDescLookup/TestDescription.java b/test/jdk/java/io/FastSerializer/concurrentClassDescLookup/TestDescription.java new file mode 100644 index 000000000..d83578255 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/concurrentClassDescLookup/TestDescription.java @@ -0,0 +1,21 @@ +/* +*- @TestCaseID:FastSerializer/ConcurrentClassDescLookup +*- @TestCaseName:ConcurrentClassDescLookup +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @summary Verify that concurrent class descriptor lookups function properly, + * even when class descriptor initialization is slow or throws an + * exception. + * @library /test/jdk/java/io/Serializable/concurrentClassDescLookup + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer ConcurrentClassDescLookup + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/corruptedUTFConsumption/TestDescription.java b/test/jdk/java/io/FastSerializer/corruptedUTFConsumption/TestDescription.java new file mode 100644 index 000000000..ee7f36c88 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/corruptedUTFConsumption/TestDescription.java @@ -0,0 +1,25 @@ +/* +*- @TestCaseID:FastSerializer/CorruptedUTFConsumption +*- @TestCaseName:CorruptedUTFConsumption +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4450867 + * @summary Although technically the behavior of ObjectInputStream following a + * UTFDataFormatException is unspecified, verify that + * ObjectInputStream consumes at most the expected number of utf + * bytes, even if the last byte(s) of the utf string indicate that the + * string overflows its expected length. + * @key randomness + * @library /test/jdk/java/io/Serializable/corruptedUTFConsumption + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer CorruptedUTFConsumption + */ diff --git a/test/jdk/java/io/FastSerializer/defaultDataEnd/TestDescription.java b/test/jdk/java/io/FastSerializer/defaultDataEnd/TestDescription.java new file mode 100644 index 000000000..920235af9 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/defaultDataEnd/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:FastSerializer/DefaultDataEnd +*- @TestCaseName:DefaultDataEnd +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4360508 + * @summary Verify that a custom readObject() method reading in data written + * via default serialization cannot read past the end of the default + * data. + * @library /test/jdk/java/io/Serializable/defaultDataEnd + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer DefaultDataEnd + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/defaultReadObjectCNFException/TestDescription.java b/test/jdk/java/io/FastSerializer/defaultReadObjectCNFException/TestDescription.java new file mode 100644 index 000000000..19b1a051c --- /dev/null +++ b/test/jdk/java/io/FastSerializer/defaultReadObjectCNFException/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:FastSerializer/DefaultReadObjectCNFException +*- @TestCaseName:DefaultReadObjectCNFException +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4662327 + * @summary Verify that ObjectInputStream.defaultReadObject() throws a + * ClassNotFoundException if any of the non-primitive field values it + * reads in are tagged with ClassNotFoundExceptions. + * @library /test/jdk/java/io/Serializable/defaultReadObjectCNFException + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer DefaultReadObjectCNFException + */ diff --git a/test/jdk/java/io/FastSerializer/diffExtern/Foo.ser b/test/jdk/java/io/FastSerializer/diffExtern/Foo.ser new file mode 100644 index 0000000000000000000000000000000000000000..8cd50316fce9ed57f5fc7a7c1ab8c519dca8fdf4 GIT binary patch literal 87 zcmcb2ih;Gbh=JKHKfj`cfz=~5Cnvw0g@J*Av7)$;p^kw8C>Wk!l#>D$WP%H_xaa3X Q#F*h?%ubc5U}Y>70O{%!v;Y7A literal 0 HcmV?d00001 diff --git a/test/jdk/java/io/FastSerializer/diffExtern/Foo2.ser b/test/jdk/java/io/FastSerializer/diffExtern/Foo2.ser new file mode 100644 index 0000000000000000000000000000000000000000..617df1b49bce22c00c35b16b144cfd76d8502fb6 GIT binary patch literal 79 ycmcb2ih;Gbh=JKHKfj`cf!V1twVZ{4fq}82xR9ZafdND?fkl`wM3^x|SSkSYv=Ep8 literal 0 HcmV?d00001 diff --git a/test/jdk/java/io/FastSerializer/diffExtern/addField.java b/test/jdk/java/io/FastSerializer/diffExtern/addField.java new file mode 100644 index 000000000..dcc5ca6fa --- /dev/null +++ b/test/jdk/java/io/FastSerializer/diffExtern/addField.java @@ -0,0 +1,93 @@ +/* +*- @TestCaseID:FastSerializer/Extern/addField +*- @TestCaseName:Extern/addField +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test add field on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true addField +*/ + + +import java.io.*; + +class Foo implements Externalizable { + int i ; + int a; + String s ; + public Foo(){} + Foo (int i, int a, String s) { + this.i = i; + this.s = s; + this.a = a; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + a = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + out.writeInt(a); + } + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s) && this.a == obj.a); + } +} + + +public class addField { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo f1 = new Foo(1,0,"Hello"); + Foo f2 = new Foo(2,0,"World"); + Foo f3 = new Foo(3,0,"Good"); + Foo f4 = new Foo(4,0,"Bye"); + String testsrc = System.getProperty("test.src"); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream(testsrc+"/Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + throw ex; + }catch (EOFException ex2){ + System.out.println("Expected Exception"); + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream(testsrc+"/Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + throw ex; + }catch (EOFException ex2){ + System.out.println("Expected Exception"); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/diffExtern/addclass.java b/test/jdk/java/io/FastSerializer/diffExtern/addclass.java new file mode 100644 index 000000000..f040d59b9 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/diffExtern/addclass.java @@ -0,0 +1,96 @@ +/* +*- @TestCaseID:FastSerializer//Extern/addclass +*- @TestCaseName:Extern/addclass +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test add Class on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true addclass +*/ + + +import java.io.*; + +class parent { + parent(int i, String s) { + this.i = i; + this.s = s; + } + int i; + String s; +} + +class Foo extends parent implements Externalizable { + int i ; + String s ; + public Foo(){ + super(0,""); + } + Foo (int i, String s) { + super(0,""); + this.i = i; + this.s = s; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s) ); + } +} + +public class addclass { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + String testsrc = System.getProperty("test.src"); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream(testsrc+"/Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + throw ex; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream(testsrc+"/Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + throw ex; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/diffExtern/changeModifier.java b/test/jdk/java/io/FastSerializer/diffExtern/changeModifier.java new file mode 100644 index 000000000..4809be275 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/diffExtern/changeModifier.java @@ -0,0 +1,84 @@ +/* +*- @TestCaseID:FastSerializer/Extern/changeModifier +*- @TestCaseName:Extern/changeModifier +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test change Modifier on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true changeModifier +*/ + + +import java.io.*; + +class Foo implements Externalizable { + int i ; + private String s ; + public Foo(){} + Foo (int i, String s) { + this.i = i; + this.s = s; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s) ); + } +} + +public class changeModifier { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + String testsrc = System.getProperty("test.src"); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream(testsrc+"/Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + throw ex; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream(testsrc+"/Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + throw ex; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/diffExtern/deletField.java b/test/jdk/java/io/FastSerializer/diffExtern/deletField.java new file mode 100644 index 000000000..9e28023ce --- /dev/null +++ b/test/jdk/java/io/FastSerializer/diffExtern/deletField.java @@ -0,0 +1,86 @@ +/* +*- @TestCaseID:FastSerializer/Extern/deletField +*- @TestCaseName:Extern/deletField +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test delet field on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true deletField +*/ + + +import java.io.*; + +class Foo implements Externalizable { + int i ; + + public Foo () { + } + public Foo (int i) { + this.i = i; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeInt(i); + } + public boolean equals(Foo obj) { + return (this.i == obj.i); + } +} + +public class deletField { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo f1 = new Foo(1); + Foo f2 = new Foo(2); + Foo f3 = new Foo(3); + Foo f4 = new Foo(4); + String testsrc = System.getProperty("test.src"); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream(testsrc+"/Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + throw ex; + }catch (EOFException ex2){ + System.out.println("Expected Exception"); + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream(testsrc+"/Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + throw ex; + }catch (EOFException ex2){ + System.out.println("Expected Exception"); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/diffExtern/removeStatic.java b/test/jdk/java/io/FastSerializer/diffExtern/removeStatic.java new file mode 100644 index 000000000..ba9fb180c --- /dev/null +++ b/test/jdk/java/io/FastSerializer/diffExtern/removeStatic.java @@ -0,0 +1,85 @@ +/* +*- @TestCaseID:FastSerializer/removeStatic +*- @TestCaseName:removeStatic +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test remove static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true removeStatic +*/ + + +import java.io.*; + +class Foo implements Externalizable { + int i ; + String s ; + public Foo(){} + Foo (int i, String s) { + this.i = i; + this.s = s; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + public boolean equals(Foo obj) { + return (this.i == obj.i ); + } +} + +public class removeStatic { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + + String testsrc = System.getProperty("test.src"); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream(testsrc+"/Foo2.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + throw ex; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream(testsrc+"/Foo2.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + throw ex; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/diffExtern/staticField.java b/test/jdk/java/io/FastSerializer/diffExtern/staticField.java new file mode 100644 index 000000000..896776ae2 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/diffExtern/staticField.java @@ -0,0 +1,86 @@ +/* +*- @TestCaseID:FastSerializer/staticField +*- @TestCaseName:staticField +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test change field to static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true staticField +*/ + + +import java.io.*; + + +class Foo implements Externalizable { + int i ; + static String s ; + public Foo(){} + Foo (int i, String s) { + this.i = i; + this.s = s; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s) ); + } +} + +public class staticField { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + + ObjectInputStream oin = new ObjectInputStream(new FileInputStream(testsrc+"/Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream(testsrc+"/Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/diffSer/Foo.ser b/test/jdk/java/io/FastSerializer/diffSer/Foo.ser new file mode 100644 index 0000000000000000000000000000000000000000..e4ba8874c08229ed20a49569e2d36c95cd3c32fa GIT binary patch literal 46 lcmcb2ih;Gbh=JKHKfi*3fq}8Okf9DpGcYj0S"; + next = null; + } + + public SerialDriver(String name, SerialDriver next) { + this.name = name; + this.next = next; + } + + static boolean serialize; + static boolean deserialize; + + public static void main(String args[]) throws Exception { + SerialDriver obj = new SerialDriver("SerialDriver_2", + new SerialDriver()); + SerialDriver[] array = new SerialDriver[5]; + for (int i = 0; i < array.length; i++) + array[i] = new SerialDriver("SerialDriver_1_" + i, new SerialDriver()); + + /* + * see if we are serializing or deserializing. + * The ability to deserialize or serialize allows + * us to see the bidirectional readability and writeability + */ + if (args.length == 1) { + if (args[0].equals("-d")) { + deserialize = true; + } else if (args[0].equals("-s")) { + serialize = true; + } else { + usage(); + throw new Exception("incorrect command line arguments"); + } + } else { + usage(); + throw new Exception("incorrect command line arguments"); + } + + File f = new File("stream.ser"); + if (serialize) { + // Serialize the subclass + try (FileOutputStream fo = new FileOutputStream(f); + ObjectOutputStream so = new ObjectOutputStream(fo)) + { + so.writeObject(obj); + /* Skip arrays since they do not work with rename yet. + The serialVersionUID changes due to the name change + and there is no way to set the serialVersionUID for an + array. */ + so.writeObject(array); + } catch (Exception e) { + System.out.println(e); + throw e; + } + } + if (deserialize) { + // Deserialize the subclass + try (FileInputStream fi = new FileInputStream(f); + ExtendedObjectInputStream si = new ExtendedObjectInputStream(fi)) + { + si.addRenamedClassName("test.SerialDriver", "install.SerialDriver"); + si.addRenamedClassName("[Ltest.SerialDriver;", + "[Linstall.SerialDriver"); + obj = (SerialDriver) si.readObject(); + array = (SerialDriver[]) si.readObject(); + } catch (Exception e) { + System.out.println(e); + throw e; + } + System.out.println(); + System.out.println("Printing deserialized class: "); + System.out.println(); + System.out.println(obj.toString()); + System.out.println(); + } + } + + + public String toString() { + String nextString = next != null ? next.toString() : ""; + return "name =" + name + " next = <" + nextString + ">"; + } + + /** + * Prints out the usage + */ + static void usage() { + System.out.println("Usage:"); + System.out.println(" -s (in order to serialize)"); + System.out.println(" -d (in order to deserialize)"); + } +} diff --git a/test/jdk/java/io/FastSerializer/evolution/RenamePackage/test/SerialDriver.java b/test/jdk/java/io/FastSerializer/evolution/RenamePackage/test/SerialDriver.java new file mode 100644 index 000000000..651eb8deb --- /dev/null +++ b/test/jdk/java/io/FastSerializer/evolution/RenamePackage/test/SerialDriver.java @@ -0,0 +1,114 @@ + + +/* + * + * @bug 4087295 + * @build install/SerialDriver.java test/SerialDriver.java extension/ExtendedObjectInputStream.java + * @summary Enable resolveClass() to accommodate package renaming. + * This fix enables one to implement a resolveClass method that maps a + * Serializable class within a serialization stream to the same class + * in a different package within the JVM runtime. See run shell script + * for instructions on how to run this test. + */ + +package test; + +import java.io.*; +import extension.ExtendedObjectInputStream; + +public class SerialDriver implements Serializable { + private static final long serialVersionUID = 1L; + String name; + SerialDriver next; + + public SerialDriver() { + name = ""; + next = null; + } + + public SerialDriver(String name, SerialDriver next) { + this.name = name; + this.next = next; + } + + static boolean serialize = false; + static boolean deserialize = false; + + public static void main(String args[]) throws Exception { + SerialDriver obj = new SerialDriver("SerialDriver_1", new SerialDriver()); + SerialDriver[] array = new SerialDriver[5]; + for (int i = 0; i < array.length; i++) + array[i] = new SerialDriver("SerialDriver_1_" + i, new SerialDriver()); + + /* + * see if we are serializing or deserializing. + * The ability to deserialize or serialize allows + * us to see the bidirectional readability and writeability + */ + if (args.length == 1) { + if (args[0].equals("-d")) { + deserialize = true; + } else if (args[0].equals("-s")) { + serialize = true; + } else { + usage(); + throw new Exception("incorrect command line arguments"); + } + } else { + usage(); + throw new Exception("incorrect command line arguments"); + } + + File f = new File("stream.ser"); + if (serialize) { + // Serialize the subclass + try (FileOutputStream fo = new FileOutputStream(f); + ObjectOutputStream so = new ObjectOutputStream(fo)) + { + so.writeObject(obj); + /* Comment out since renaming arrays does not work + since it changes the serialVersionUID. */ + so.writeObject(array); + } catch (Exception e) { + System.out.println(e); + throw e; + } + } + if (deserialize) { + // Deserialize the subclass + try (FileInputStream fi = new FileInputStream(f); + ExtendedObjectInputStream si = new ExtendedObjectInputStream(fi)) + { + si.addRenamedClassName("install.SerialDriver", + "test.SerialDriver"); + si.addRenamedClassName("[Linstall.SerialDriver;", + "[Ltest.SerialDriver"); + obj = (SerialDriver) si.readObject(); + array = (SerialDriver[]) si.readObject(); + } catch (Exception e) { + System.out.println(e); + throw e; + } + System.out.println(); + System.out.println("Printing deserialized class: "); + System.out.println(); + System.out.println(obj.toString()); + System.out.println(); + } + } + + + public String toString() { + String nextString = next != null ? next.toString() : ""; + return "name =" + name + " next = <" + nextString + ">"; + } + + /** + * Prints out the usage + */ + static void usage() { + System.out.println("Usage:"); + System.out.println(" -s (in order to serialize)"); + System.out.println(" -d (in order to deserialize)"); + } +} diff --git a/test/jdk/java/io/FastSerializer/expectedStackTrace/TestDescription.java b/test/jdk/java/io/FastSerializer/expectedStackTrace/TestDescription.java new file mode 100644 index 000000000..1df307342 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/expectedStackTrace/TestDescription.java @@ -0,0 +1,25 @@ +/* +*- @TestCaseID:FastSerializer/expectedStackTrace +*- @TestCaseName:expectedStackTrace +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 6317435 7110700 + * @summary Verify that stack trace contains a proper cause of + * InvalidClassException (methods: checkSerialize, + * checkDeserialize or checkDefaultSerialize) + * + * @author Andrey Ozerov + * @library /test/jdk/java/io/Serializable/expectedStackTrace + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer ExpectedStackTrace + * + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/explicitCNFException/TestDescription.java b/test/jdk/java/io/FastSerializer/explicitCNFException/TestDescription.java new file mode 100644 index 000000000..2317c81ef --- /dev/null +++ b/test/jdk/java/io/FastSerializer/explicitCNFException/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:FastSerializer/ExplicitCNFException +*- @TestCaseName:ExplicitCNFException +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4407956 + * @summary Verify that ClassNotFoundExceptions explicitly constructed and + * thrown from with custom readObject/readExternal methods are + * propagated properly. + * @library /test/jdk/java/io/Serializable/explicitCNFException + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer ExplicitCNFException + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/failureAtomicity/Bar.template b/test/jdk/java/io/FastSerializer/failureAtomicity/Bar.template new file mode 100644 index 000000000..465bc2b5e --- /dev/null +++ b/test/jdk/java/io/FastSerializer/failureAtomicity/Bar.template @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package $package; + +import java.io.IOException; +import java.io.Serializable; +import failureAtomicity.SerialRef; + +public class Bar extends Foo implements Serializable { + static final long serialVersionUID = -0L; + + public final long barPrim; + public final String barRef; + + public final SerialRef ref; // So we can retrieve a reference to check + public $zebra_type zebraBar; // ordered alphabetically, must be last + + public Bar(int fooPrim, String fooRef, $foo_zebra_type fooZebra, + long barPrim, String barRef, $zebra_type zebra) { + super(fooPrim, fooRef, fooZebra); + this.barPrim = barPrim; + this.barRef = barRef; + this.zebraBar = zebra; + this.ref = new SerialRef(this); + } + + @Override + public String toString() { + return new StringBuilder() + .append("$package.Bar[") + .append("barPrim:").append(barPrim) + .append(", barRef:").append(barRef) + .append(", zebraBar:").append(zebraBar) + .append(", " + super.toString()) + .toString(); + } + +//$has_readObject private void readObject(java.io.ObjectInputStream in) +//$has_readObject throws IOException, ClassNotFoundException +//$has_readObject { +//$has_readObject in.defaultReadObject(); +//$has_readObject } +} diff --git a/test/jdk/java/io/FastSerializer/failureAtomicity/Foo.template b/test/jdk/java/io/FastSerializer/failureAtomicity/Foo.template new file mode 100644 index 000000000..455d34c9a --- /dev/null +++ b/test/jdk/java/io/FastSerializer/failureAtomicity/Foo.template @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package $package; + +import java.io.IOException; +import java.io.Serializable; +import failureAtomicity.SerialRef; + +public class Foo implements Serializable { + static final long serialVersionUID = -0L; + + public final int fooPrim; + public final String fooRef; + + public final SerialRef ref; // So we can retrieve a reference to check + public $zebra_type zebraFoo; // ordered alphabetically, must be last + + public Foo(int fooPrim, String fooRef, $zebra_type zebra) { + this.fooPrim = fooPrim; + this.fooRef = fooRef; + this.zebraFoo = zebra; + this.ref = new SerialRef(this); + } + + @Override + public String toString() { + return new StringBuilder() + .append("$package.Foo[") + .append("fooPrim:").append(fooPrim) + .append(", fooRef:").append(fooRef) + .append(", zebraFoo:").append(zebraFoo).append("]") + .toString(); + } + +//$has_readObject private void readObject(java.io.ObjectInputStream in) +//$has_readObject throws IOException, ClassNotFoundException +//$has_readObject { +//$has_readObject in.defaultReadObject(); +//$has_readObject } + +} diff --git a/test/jdk/java/io/FastSerializer/failureAtomicity/SerialRef.java b/test/jdk/java/io/FastSerializer/failureAtomicity/SerialRef.java new file mode 100644 index 000000000..5b7b04c80 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/failureAtomicity/SerialRef.java @@ -0,0 +1,25 @@ + +package failureAtomicity; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.Serializable; + +// For verification purposes only. + +public class SerialRef implements Serializable { + static final long serialVersionUID = -0L; + public static Object obj; + + private final Object ref; + + public SerialRef(Object ref) { + this.ref = ref; + } + + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException { + in.defaultReadObject(); + SerialRef.obj = ref; + } +} diff --git a/test/jdk/java/io/FastSerializer/failureAtomicity/TestDescription.java b/test/jdk/java/io/FastSerializer/failureAtomicity/TestDescription.java new file mode 100644 index 000000000..65a775967 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/failureAtomicity/TestDescription.java @@ -0,0 +1,24 @@ +/* +*- @TestCaseID:FastSerializer/FailureAtomicity +*- @TestCaseName:FailureAtomicity +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ +/* + * @test + * @bug 8071474 + * @summary Better failure atomicity for default read object. + * @modules jdk.compiler + * @library /test/lib /test/jdk/java/io/Serializable + * @build jdk.test.lib.Platform + * jdk.test.lib.util.FileUtils + * @build failureAtomicity.FailureAtomicity failureAtomicity.SerialRef + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer failureAtomicity.FailureAtomicity + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/finalFields/TestDescription.java b/test/jdk/java/io/FastSerializer/finalFields/TestDescription.java new file mode 100644 index 000000000..36ae8606c --- /dev/null +++ b/test/jdk/java/io/FastSerializer/finalFields/TestDescription.java @@ -0,0 +1,20 @@ +/* +*- @TestCaseID:FastSerializer/FinalFields +*- @TestCaseName:FinalFields +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4174797 + * @summary Ensure that ObjectInputStream can set final fields. + * @library /test/jdk/java/io/Serializable/finalFields + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer FinalFields + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/getSuidClinitError/TestDescription.java b/test/jdk/java/io/FastSerializer/getSuidClinitError/TestDescription.java new file mode 100644 index 000000000..3a3ee7eae --- /dev/null +++ b/test/jdk/java/io/FastSerializer/getSuidClinitError/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:FastSerializer/GetSuidClinitError +*- @TestCaseName:GetSuidClinitError +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4482966 + * @summary Verify that ObjectStreamClass.getSerialVersionUID() will not mask + * Errors (other than NoSuchMethodError) triggered by JNI query for + * static initializer method. + * @library /test/jdk/java/io/Serializable/getSuidClinitError + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer GetSuidClinitError + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/illegalHandle/TestDescription.java b/test/jdk/java/io/FastSerializer/illegalHandle/TestDescription.java new file mode 100644 index 000000000..9eb044c77 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/illegalHandle/TestDescription.java @@ -0,0 +1,20 @@ +/* +*- @TestCaseID:FastSerializer/illegalHandle +*- @TestCaseName:illegalHandle +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ +/* @test + * @bug 4357979 + * @summary Verify that ObjectInputStream throws a StreamCorruptedException if + * it reads in an out-of-bounds handle value. + * @library /test/jdk/java/io/Serializable/illegalHandle + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true Test + */ diff --git a/test/jdk/java/io/FastSerializer/illegalHandle/negativeHandle.ser b/test/jdk/java/io/FastSerializer/illegalHandle/negativeHandle.ser new file mode 100644 index 0000000000000000000000000000000000000000..627c6e860196f61a2d0cdddd3b3527e19ef3f2d7 GIT binary patch literal 15 WcmZ4UmVvc|fjKQdzmTE!|9=20=mtgr literal 0 HcmV?d00001 diff --git a/test/jdk/java/io/FastSerializer/illegalHandle/tooHighHandle.ser b/test/jdk/java/io/FastSerializer/illegalHandle/tooHighHandle.ser new file mode 100644 index 0000000000000000000000000000000000000000..0894b05fdd1716659b6ae347ae2b5d9fa341607a GIT binary patch literal 15 WcmZ4UmVvc|fjKQdzmTDhAq4;_QUt94 literal 0 HcmV?d00001 diff --git a/test/jdk/java/io/FastSerializer/inactiveRegistration/TestDescription.java b/test/jdk/java/io/FastSerializer/inactiveRegistration/TestDescription.java new file mode 100644 index 000000000..900640f2e --- /dev/null +++ b/test/jdk/java/io/FastSerializer/inactiveRegistration/TestDescription.java @@ -0,0 +1,21 @@ +/* +*- @TestCaseID:FastSerializer/inactiveRegistration +*- @TestCaseName:inactiveRegistration +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4400609 + * @summary Verify that ObjectInputStream.registerValidation() throws a + * NotActiveException when invoked on inactive stream. + * @library /test/jdk/java/io/Serializable/inactiveRegistration + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer InactiveRegistration + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/innerClass/innerExtern.java b/test/jdk/java/io/FastSerializer/innerClass/innerExtern.java new file mode 100644 index 000000000..6d212bf76 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/innerClass/innerExtern.java @@ -0,0 +1,107 @@ +/* +*- @TestCaseID:FastSerializer/innerExtern +*- @TestCaseName:innerExtern +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test static field cannot be deserialized +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true innerExtern +*/ + + +import java.io.*; + + +class Foo implements Externalizable { + static class Foo1 implements Externalizable { + public Foo1(){} + Foo1 (int i, String s) { + this.i = i; + this.s = s; + } + int i = 0; + String s ; + + public boolean equals(Foo1 obj) { + return (this.i == obj.i && this.s.equals(obj.s)); + } + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + + } + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + } + +} + +public class innerExtern { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo.Foo1 f1 = new Foo.Foo1(1,"Hello"); + Foo.Foo1 f2 = new Foo.Foo1(2,"World"); + Foo.Foo1 f3 = new Foo.Foo1(3,"Good"); + Foo.Foo1 f4 = new Foo.Foo1(4,"Bye"); + + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + Foo.Foo1 fout1 = (Foo.Foo1)oin.readObject(); + Foo.Foo1 fout2 = (Foo.Foo1)oin.readObject(); + Foo.Foo1 fout3 = (Foo.Foo1)oin.readObject(); + Foo.Foo1 fout4 = (Foo.Foo1)oin.readObject(); + oin.close(); + + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + Foo.Foo1 fout5 = (Foo.Foo1)oin2.readObject(); + Foo.Foo1 fout6 = (Foo.Foo1)oin2.readObject(); + Foo.Foo1 fout7 = (Foo.Foo1)oin2.readObject(); + Foo.Foo1 fout8 = (Foo.Foo1)oin2.readObject(); + + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/innerClass/innerSerial.java b/test/jdk/java/io/FastSerializer/innerClass/innerSerial.java new file mode 100644 index 000000000..53d09878f --- /dev/null +++ b/test/jdk/java/io/FastSerializer/innerClass/innerSerial.java @@ -0,0 +1,85 @@ +/* +*- @TestCaseID:FastSerializer/innerSerial +*- @TestCaseName:innerSerial +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test static field cannot be deserialized +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true innerSerial +*/ + + +import java.io.*; + + +class Foo implements Serializable { + static class Foo1 implements Serializable { + Foo1 (int i, String s) { + this.i = i; + this.s = s; + } + int i = 0; + String s ; + + public boolean equals(Foo1 obj) { + return (this.i == obj.i && this.s.equals(obj.s)); + } + } + +} + +public class innerSerial { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo.Foo1 f1 = new Foo.Foo1(1,"Hello"); + Foo.Foo1 f2 = new Foo.Foo1(2,"World"); + Foo.Foo1 f3 = new Foo.Foo1(3,"Good"); + Foo.Foo1 f4 = new Foo.Foo1(4,"Bye"); + + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + Foo.Foo1 fout1 = (Foo.Foo1)oin.readObject(); + Foo.Foo1 fout2 = (Foo.Foo1)oin.readObject(); + Foo.Foo1 fout3 = (Foo.Foo1)oin.readObject(); + Foo.Foo1 fout4 = (Foo.Foo1)oin.readObject(); + oin.close(); + + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + Foo.Foo1 fout5 = (Foo.Foo1)oin2.readObject(); + Foo.Foo1 fout6 = (Foo.Foo1)oin2.readObject(); + Foo.Foo1 fout7 = (Foo.Foo1)oin2.readObject(); + Foo.Foo1 fout8 = (Foo.Foo1)oin2.readObject(); + + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/logging.properties b/test/jdk/java/io/FastSerializer/logging.properties new file mode 100644 index 000000000..0d3ef9140 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/logging.properties @@ -0,0 +1,64 @@ +############################################################ +# Default Logging Configuration File +# +# You can use a different file by specifying a filename +# with the java.util.logging.config.file system property. +# For example java -Djava.util.logging.config.file=myfile +############################################################ + +############################################################ +# Global properties +############################################################ + +# "handlers" specifies a comma separated list of log Handler +# classes. These handlers will be installed during VM startup. +# Note that these classes must be on the system classpath. +# By default we only configure a ConsoleHandler, which will only +# show messages at the INFO and above levels. +handlers= java.util.logging.ConsoleHandler + +# To also add the FileHandler, use the following line instead. +#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler + +# Default global logging level. +# This specifies which kinds of events are logged across +# all loggers. For any given facility this global level +# can be overriden by a facility specific level +# Note that the ConsoleHandler also has a separate level +# setting to limit messages printed to the console. +.level= INFO + +############################################################ +# Handler specific properties. +# Describes specific configuration info for Handlers. +############################################################ + +# default file output is in user's home directory. +java.util.logging.FileHandler.pattern = %h/java%u.log +java.util.logging.FileHandler.limit = 50000 +java.util.logging.FileHandler.count = 1 +# Default number of locks FileHandler can obtain synchronously. +# This specifies maximum number of attempts to obtain lock file by FileHandler +# implemented by incrementing the unique field %u as per FileHandler API documentation. +java.util.logging.FileHandler.maxLocks = 100 +java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter + +# Limit the message that are printed on the console to INFO and above. +java.util.logging.ConsoleHandler.level = FINE +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + +# Example to customize the SimpleFormatter output format +# to print one-line log message like this: +# : [] +# +# java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n + +############################################################ +# Facility specific properties. +# Provides extra control for each logger. +############################################################ + +# For example, set the com.xyz.foo logger to only log SEVERE +# messages: +com.xyz.foo.level = SEVERE +fastSerializer.level= FINE diff --git a/test/jdk/java/io/FastSerializer/longString/TestDescription.java b/test/jdk/java/io/FastSerializer/longString/TestDescription.java new file mode 100644 index 000000000..70e4c971f --- /dev/null +++ b/test/jdk/java/io/FastSerializer/longString/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:FastSerializer/LongString +*- @TestCaseName:LongString +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4217676 + * @summary Ensure that object streams support serialization of long strings + * (strings whose UTF representation > 64k in length) + * @key randomness + * @library /test/jdk/java/io/Serializable/longString + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer LongString + */ diff --git a/test/jdk/java/io/FastSerializer/longString/mesg.ser b/test/jdk/java/io/FastSerializer/longString/mesg.ser new file mode 100644 index 0000000000000000000000000000000000000000..cfa2616feb173118bc28ffe47c4487b06fc46f7e GIT binary patch literal 29 kcmcb2ih;F+LCiO`xHvIARUtD^Aw54QB{feWEi)$-0GavT99AyEcVT4^CUNCuVr481VX5Q5rURRYE~rJw_dX={Tv`;WNDtsN7xhx$|!3LTZm?&z{F&6}`4U?exLK-jI$F!robN!+TP>|vR(^-o`2ZQFX3oF2W8+xf0U&-MxjM*qxXZ24;LRkLappLQ4t6Kme;Lmd{^IhP*gEtMQgY6Rkwb*vZ zdi@HyuMmGwD0$b&pL~P(lp>uk>?YjjbCF*Nm?p~vYfRxe$(-(pp0UpnmFm}^&z+yh foIL%G>=ovJb2d0 list = new ArrayList<>(); + list.add(i); + list.add(s); + return list; + } +} + +class MyObjectOutputStream extends ObjectOutputStream{ + + public MyObjectOutputStream(OutputStream out) throws IOException { + super(out); + } + + @Override + protected void annotateClass(Class c)throws IOException + { + if(c == Foo.class) + { + super.annotateClass(c); + return ; + }else { + throw new InvalidClassException( + "Unauthorized deserialization attempt"); + } + } + + +} + +public class overWriteAnnotateClass { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + MyObjectOutputStream oout = new MyObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + ArrayList fout1 = (ArrayList)oin.readObject(); + ArrayList fout2 = (ArrayList)oin.readObject(); + ArrayList fout3 = (ArrayList)oin.readObject(); + ArrayList fout4 = (ArrayList)oin.readObject(); + oin.close(); + if(!f1.equals(fout1) || !f2.equals(fout2) ||!f3.equals(fout3) ||!f4.equals(fout4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + ArrayList fout5 = (ArrayList)oin2.readObject(); + ArrayList fout6 = (ArrayList)oin2.readObject(); + ArrayList fout7 = (ArrayList)oin2.readObject(); + ArrayList fout8 = (ArrayList)oin2.readObject(); + if(!f1.equals(fout5) || !f2.equals(fout6) ||!f3.equals(fout7) ||!f4.equals(fout8)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/overWriteExtern/overWriteReadResolve.java b/test/jdk/java/io/FastSerializer/overWriteExtern/overWriteReadResolve.java new file mode 100644 index 000000000..95bc1fa84 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/overWriteExtern/overWriteReadResolve.java @@ -0,0 +1,100 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/Extern/overWriteReadResolve +*- @TestCaseName:Extern/overWriteReadResolve +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test change field to static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true overWriteReadResolve +*/ + + +import java.io.*; +import java.util.ArrayList; + +class Foo implements Externalizable { + int i ; + String s ; + public Foo(){} + Foo (int i, String s) { + this.i = i; + this.s = s; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + + public boolean equals(ArrayList obj) { + return (this.i == (int)obj.get(0) && this.s.equals(obj.get(1))); + } + + private Object readResolve() throws ObjectStreamException { + ArrayList list = new ArrayList<>(); + list.add(i); + list.add(s); + return list; + } +} + + +public class overWriteReadResolve { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + ArrayList fout1 = (ArrayList)oin.readObject(); + ArrayList fout2 = (ArrayList)oin.readObject(); + ArrayList fout3 = (ArrayList)oin.readObject(); + ArrayList fout4 = (ArrayList)oin.readObject(); + oin.close(); + if(!f1.equals(fout1) || !f2.equals(fout2) ||!f3.equals(fout3) ||!f4.equals(fout4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + ArrayList fout5 = (ArrayList)oin2.readObject(); + ArrayList fout6 = (ArrayList)oin2.readObject(); + ArrayList fout7 = (ArrayList)oin2.readObject(); + ArrayList fout8 = (ArrayList)oin2.readObject(); + if(!f1.equals(fout5) || !f2.equals(fout6) ||!f3.equals(fout7) ||!f4.equals(fout8)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/overWriteExtern/overWriteResolveClass.java b/test/jdk/java/io/FastSerializer/overWriteExtern/overWriteResolveClass.java new file mode 100644 index 000000000..0e3c7b3ad --- /dev/null +++ b/test/jdk/java/io/FastSerializer/overWriteExtern/overWriteResolveClass.java @@ -0,0 +1,114 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/Extern/overWriteResolveClass +*- @TestCaseName:Extern/overWriteResolveClass +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test change field to static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true overWriteResolveClass +*/ + + +import java.io.*; +import java.util.ArrayList; + +class Foo implements Externalizable { + int i ; + String s ; + public Foo(){} + Foo (int i, String s) { + this.i = i; + this.s = s; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + + public boolean equals(ArrayList obj) { + return (this.i == (int)obj.get(0) && this.s.equals(obj.get(1))); + } + + private Object readResolve() throws ObjectStreamException { + ArrayList list = new ArrayList<>(); + list.add(i); + list.add(s); + return list; + } +} + +class MyObjectInputStream extends ObjectInputStream { + public MyObjectInputStream(InputStream in) throws IOException { + super(in); + } + @Override + protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { + if (!desc.getName().equals(Foo.class.getName())) { + throw new InvalidClassException( + "Unauthorized deserialization attempt", + desc.getName()); + } + return super.resolveClass(desc); + } +} + +public class overWriteResolveClass { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + MyObjectInputStream oin = new MyObjectInputStream(new FileInputStream("Foo.ser")); + try{ + ArrayList fout1 = (ArrayList)oin.readObject(); + ArrayList fout2 = (ArrayList)oin.readObject(); + ArrayList fout3 = (ArrayList)oin.readObject(); + ArrayList fout4 = (ArrayList)oin.readObject(); + oin.close(); + if(!f1.equals(fout1) || !f2.equals(fout2) ||!f3.equals(fout3) ||!f4.equals(fout4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + MyObjectInputStream oin2 = new MyObjectInputStream(new FileInputStream("Foo.ser")); + try { + ArrayList fout5 = (ArrayList)oin2.readObject(); + ArrayList fout6 = (ArrayList)oin2.readObject(); + ArrayList fout7 = (ArrayList)oin2.readObject(); + ArrayList fout8 = (ArrayList)oin2.readObject(); + if(!f1.equals(fout5) || !f2.equals(fout6) ||!f3.equals(fout7) ||!f4.equals(fout8)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/overWriteExtern/overWriteWriteReplace.java b/test/jdk/java/io/FastSerializer/overWriteExtern/overWriteWriteReplace.java new file mode 100644 index 000000000..fc8be4cee --- /dev/null +++ b/test/jdk/java/io/FastSerializer/overWriteExtern/overWriteWriteReplace.java @@ -0,0 +1,99 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/Extern/overWriteWriteReplace +*- @TestCaseName:Extern/overWriteWriteReplace +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test change field to static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true overWriteWriteReplace +*/ + + +import java.io.*; +import java.util.ArrayList; + +class Foo implements Externalizable { + int i ; + String s ; + public Foo(){} + Foo (int i, String s) { + this.i = i; + this.s = s; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + + public boolean equals(ArrayList obj) { + return (this.i == (int)obj.get(0) && this.s.equals(obj.get(1))); + } + private Object writeReplace() throws ObjectStreamException { + ArrayList list = new ArrayList<>(); + list.add(i); + list.add(s); + return list; + } +} + + +public class overWriteWriteReplace { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + ArrayList fout1 = (ArrayList)oin.readObject(); + ArrayList fout2 = (ArrayList)oin.readObject(); + ArrayList fout3 = (ArrayList)oin.readObject(); + ArrayList fout4 = (ArrayList)oin.readObject(); + oin.close(); + if(!f1.equals(fout1) || !f2.equals(fout2) ||!f3.equals(fout3) ||!f4.equals(fout4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + ArrayList fout5 = (ArrayList)oin2.readObject(); + ArrayList fout6 = (ArrayList)oin2.readObject(); + ArrayList fout7 = (ArrayList)oin2.readObject(); + ArrayList fout8 = (ArrayList)oin2.readObject(); + if(!f1.equals(fout5) || !f2.equals(fout6) ||!f3.equals(fout7) ||!f4.equals(fout8)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/overWriteSer/overWriteAnnotateClass.java b/test/jdk/java/io/FastSerializer/overWriteSer/overWriteAnnotateClass.java new file mode 100644 index 000000000..5dee5bdf9 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/overWriteSer/overWriteAnnotateClass.java @@ -0,0 +1,108 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/Ser/overWriteAnnotateClass +*- @TestCaseName:overWriteAnnotateClass +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test change field to static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true overWriteAnnotateClass +*/ + + +import java.io.*; +import java.util.ArrayList; + +class Foo implements Serializable { + Foo (int i, String s) { + this.i = i; + this.s = s; + } + int i; + String s ; + + public boolean equals(ArrayList obj) { + return (this.i == (int)obj.get(0) && this.s.equals(obj.get(1))); + } + + private Object readResolve() throws ObjectStreamException { + ArrayList list = new ArrayList<>(); + list.add(i); + list.add(s); + return list; + } +} + +class MyObjectOutputStream extends ObjectOutputStream{ + + public MyObjectOutputStream(OutputStream out) throws IOException { + super(out); + } + + @Override + protected void annotateClass(Class c)throws IOException + { + if(c == Foo.class) + { + super.annotateClass(c); + return ; + }else { + throw new InvalidClassException( + "Unauthorized deserialization attempt"); + } + } + + +} + +public class overWriteAnnotateClass { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + MyObjectOutputStream oout = new MyObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + ArrayList fout1 = (ArrayList)oin.readObject(); + ArrayList fout2 = (ArrayList)oin.readObject(); + ArrayList fout3 = (ArrayList)oin.readObject(); + ArrayList fout4 = (ArrayList)oin.readObject(); + oin.close(); + if(!f1.equals(fout1) || !f2.equals(fout2) ||!f3.equals(fout3) ||!f4.equals(fout4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + ArrayList fout5 = (ArrayList)oin2.readObject(); + ArrayList fout6 = (ArrayList)oin2.readObject(); + ArrayList fout7 = (ArrayList)oin2.readObject(); + ArrayList fout8 = (ArrayList)oin2.readObject(); + if(!f1.equals(fout5) || !f2.equals(fout6) ||!f3.equals(fout7) ||!f4.equals(fout8)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/overWriteSer/overWriteReadResolve.java b/test/jdk/java/io/FastSerializer/overWriteSer/overWriteReadResolve.java new file mode 100644 index 000000000..fa4d5ca2a --- /dev/null +++ b/test/jdk/java/io/FastSerializer/overWriteSer/overWriteReadResolve.java @@ -0,0 +1,86 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/Ser/overWriteReadResolve +*- @TestCaseName:Ser/overWriteReadResolve +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test change field to static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true overWriteReadResolve +*/ + + +import java.io.*; +import java.util.ArrayList; + +class Foo implements Serializable { + Foo (int i, String s) { + this.i = i; + this.s = s; + } + int i; + String s ; + + public boolean equals(ArrayList obj) { + return (this.i == (int)obj.get(0) && this.s.equals(obj.get(1))); + } + + private Object readResolve() throws ObjectStreamException { + ArrayList list = new ArrayList<>(); + list.add(i); + list.add(s); + return list; + } +} + +public class overWriteReadResolve { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + ArrayList fout1 = (ArrayList)oin.readObject(); + ArrayList fout2 = (ArrayList)oin.readObject(); + ArrayList fout3 = (ArrayList)oin.readObject(); + ArrayList fout4 = (ArrayList)oin.readObject(); + oin.close(); + if(!f1.equals(fout1) || !f2.equals(fout2) ||!f3.equals(fout3) ||!f4.equals(fout4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + ArrayList fout5 = (ArrayList)oin2.readObject(); + ArrayList fout6 = (ArrayList)oin2.readObject(); + ArrayList fout7 = (ArrayList)oin2.readObject(); + ArrayList fout8 = (ArrayList)oin2.readObject(); + if(!f1.equals(fout5) || !f2.equals(fout6) ||!f3.equals(fout7) ||!f4.equals(fout8)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/overWriteSer/overWriteResolveClass.java b/test/jdk/java/io/FastSerializer/overWriteSer/overWriteResolveClass.java new file mode 100644 index 000000000..cff0efc9e --- /dev/null +++ b/test/jdk/java/io/FastSerializer/overWriteSer/overWriteResolveClass.java @@ -0,0 +1,102 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/Ser/overWriteResolveClass +*- @TestCaseName:Ser/overWriteResolveClass +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test change field to static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true overWriteResolveClass +*/ + + +import java.io.*; +import java.util.ArrayList; + +class Foo implements Serializable { + Foo (int i, String s) { + this.i = i; + this.s = s; + } + int i; + String s ; + + public boolean equals(ArrayList obj) { + return (this.i == (int)obj.get(0) && this.s.equals(obj.get(1))); + } + + private Object readResolve() throws ObjectStreamException { + ArrayList list = new ArrayList<>(); + list.add(i); + list.add(s); + return list; + } +} + +class MyObjectInputStream extends ObjectInputStream { + + public MyObjectInputStream(InputStream in) throws IOException { + super(in); + } + @Override + protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { + if (!desc.getName().equals(Foo.class.getName())) { + throw new InvalidClassException( + "Unauthorized deserialization attempt", + desc.getName()); + } + return super.resolveClass(desc); + } +} + +public class overWriteResolveClass { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + MyObjectInputStream oin = new MyObjectInputStream(new FileInputStream("Foo.ser")); + try{ + ArrayList fout1 = (ArrayList)oin.readObject(); + ArrayList fout2 = (ArrayList)oin.readObject(); + ArrayList fout3 = (ArrayList)oin.readObject(); + ArrayList fout4 = (ArrayList)oin.readObject(); + oin.close(); + if(!f1.equals(fout1) || !f2.equals(fout2) ||!f3.equals(fout3) ||!f4.equals(fout4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + MyObjectInputStream oin2 = new MyObjectInputStream(new FileInputStream("Foo.ser")); + try { + ArrayList fout5 = (ArrayList)oin2.readObject(); + ArrayList fout6 = (ArrayList)oin2.readObject(); + ArrayList fout7 = (ArrayList)oin2.readObject(); + ArrayList fout8 = (ArrayList)oin2.readObject(); + if(!f1.equals(fout5) || !f2.equals(fout6) ||!f3.equals(fout7) ||!f4.equals(fout8)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/overWriteSer/overWriteWriteObject.java b/test/jdk/java/io/FastSerializer/overWriteSer/overWriteWriteObject.java new file mode 100644 index 000000000..8b1b091e8 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/overWriteSer/overWriteWriteObject.java @@ -0,0 +1,81 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/overWriteWriteObject +*- @TestCaseName:overWriteWriteObject +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test serialize and deserialize of normal object +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true overWriteWriteObject +*/ + + +import java.io.*; + +class Foo implements Serializable { + Foo (int i, String s) { + this.i = i; + this.s = s; + } + int i; + String s ; + + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s)); + } + + private void writeObject(java.io.ObjectOutputStream stream) + throws IOException { + stream.writeObject(s); + stream.writeInt(i); + } + + private void readObject(java.io.ObjectInputStream stream) + throws IOException, ClassNotFoundException { + s = (String) stream.readObject(); + i = stream.readInt(); + } +} + +public class overWriteWriteObject { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo4.ser")); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo4.ser")); + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo4.ser")); + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/overWriteSer/overWriteWriteReplace.java b/test/jdk/java/io/FastSerializer/overWriteSer/overWriteWriteReplace.java new file mode 100644 index 000000000..c794132aa --- /dev/null +++ b/test/jdk/java/io/FastSerializer/overWriteSer/overWriteWriteReplace.java @@ -0,0 +1,85 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/Ser/overWriteWriteReplace +*- @TestCaseName:Ser/overWriteWriteReplace +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test change field to static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true overWriteWriteReplace +*/ + + +import java.io.*; +import java.util.ArrayList; + +class Foo implements Serializable { + Foo (int i, String s) { + this.i = i; + this.s = s; + } + int i; + String s ; + + public boolean equals(ArrayList obj) { + return (this.i == (int)obj.get(0) && this.s.equals(obj.get(1))); + } + private Object writeReplace() throws ObjectStreamException { + ArrayList list = new ArrayList<>(); + list.add(i); + list.add(s); + return list; + } +} + +public class overWriteWriteReplace { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + ArrayList fout1 = (ArrayList)oin.readObject(); + ArrayList fout2 = (ArrayList)oin.readObject(); + ArrayList fout3 = (ArrayList)oin.readObject(); + ArrayList fout4 = (ArrayList)oin.readObject(); + oin.close(); + if(!f1.equals(fout1) || !f2.equals(fout2) ||!f3.equals(fout3) ||!f4.equals(fout4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + ArrayList fout5 = (ArrayList)oin2.readObject(); + ArrayList fout6 = (ArrayList)oin2.readObject(); + ArrayList fout7 = (ArrayList)oin2.readObject(); + ArrayList fout8 = (ArrayList)oin2.readObject(); + if(!f1.equals(fout5) || !f2.equals(fout6) ||!f3.equals(fout7) ||!f4.equals(fout8)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/packageAccess/A.java b/test/jdk/java/io/FastSerializer/packageAccess/A.java new file mode 100644 index 000000000..ea6b006ce --- /dev/null +++ b/test/jdk/java/io/FastSerializer/packageAccess/A.java @@ -0,0 +1,20 @@ + + +/* + * @bug 4765255 + * @summary Verify proper functioning of package equality checks used to + * determine accessibility of superclass constructor and inherited + * writeReplace/readResolve methods. + */ + +public class A { + + static boolean packagePrivateConstructorInvoked = false; + + A() { + packagePrivateConstructorInvoked = true; + } + + public A(int throwaway) { + } +} diff --git a/test/jdk/java/io/FastSerializer/packageAccess/B.java b/test/jdk/java/io/FastSerializer/packageAccess/B.java new file mode 100644 index 000000000..e750ae72e --- /dev/null +++ b/test/jdk/java/io/FastSerializer/packageAccess/B.java @@ -0,0 +1,14 @@ + + +/* + * @bug 4765255 + * @summary Verify proper functioning of package equality checks used to + * determine accessibility of superclass constructor and inherited + * writeReplace/readResolve methods. + */ + +public class B extends A implements java.io.Serializable { + public B() { + super(0); + } +} diff --git a/test/jdk/java/io/FastSerializer/packageAccess/C.java b/test/jdk/java/io/FastSerializer/packageAccess/C.java new file mode 100644 index 000000000..af8bf0b9b --- /dev/null +++ b/test/jdk/java/io/FastSerializer/packageAccess/C.java @@ -0,0 +1,20 @@ + + +/* + * @bug 4765255 + * @summary Verify proper functioning of package equality checks used to + * determine accessibility of superclass constructor and inherited + * writeReplace/readResolve methods. + */ + +import java.io.*; + +public class C implements Serializable { + Object writeReplace() throws ObjectStreamException { + throw new Error("package-private writeReplace called"); + } + + Object readResolve() throws ObjectStreamException { + throw new Error("package-private readResolve called"); + } +} diff --git a/test/jdk/java/io/FastSerializer/packageAccess/D.java b/test/jdk/java/io/FastSerializer/packageAccess/D.java new file mode 100644 index 000000000..f9d80fef5 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/packageAccess/D.java @@ -0,0 +1,11 @@ + + +/* + * @bug 4765255 + * @summary Verify proper functioning of package equality checks used to + * determine accessibility of superclass constructor and inherited + * writeReplace/readResolve methods. + */ + +public class D extends C implements java.io.Serializable { +} diff --git a/test/jdk/java/io/FastSerializer/packageAccess/TestDescription.java b/test/jdk/java/io/FastSerializer/packageAccess/TestDescription.java new file mode 100644 index 000000000..20eff38c0 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/packageAccess/TestDescription.java @@ -0,0 +1,24 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/packageAccess +*- @TestCaseName:packageAccess +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* + * @test + * @bug 4765255 + * @library /test/lib /test/jdk/java/io/Serializable/packageAccess + * @build jdk.test.lib.util.JarUtils A B C D PackageAccessTest + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer PackageAccessTest + * @summary Verify proper functioning of package equality checks used to + * determine accessibility of superclass constructor and inherited + * writeReplace/readResolve methods. + */ diff --git a/test/jdk/java/io/FastSerializer/parents/EvolvedClass.java b/test/jdk/java/io/FastSerializer/parents/EvolvedClass.java new file mode 100644 index 000000000..aaff27452 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/parents/EvolvedClass.java @@ -0,0 +1,66 @@ + + +/* + * @bug 4186885 + */ + +import java.io.*; + +public class EvolvedClass { + public static void main(String args[]) throws Exception{ + ASubClass corg = new ASubClass(1, "SerializedByEvolvedClass"); + ASubClass cnew = null; + + // Deserialize in to new class object + FileInputStream fi = new FileInputStream("parents.ser"); + try { + ObjectInputStream si = new ObjectInputStream(fi); + cnew = (ASubClass) si.readObject(); + } finally { + fi.close(); + } + + System.out.println("Printing the deserialized class: "); + System.out.println(); + System.out.println(cnew); + } +} + + +/* During deserialization, the no-arg constructor of a serializable base class + * must not be invoked. + */ +class ASuperClass implements Serializable { + String name; + + ASuperClass() { + /* + * This method is not to be executed during deserialization for this + * example. Must call no-arg constructor of class Object which is the + * base class for ASuperClass. + */ + throw new Error("ASuperClass: Wrong no-arg constructor invoked"); + } + + ASuperClass(String name) { + this.name = new String(name); + } + + public String toString() { + return("Name: " + name); + } +} + +class ASubClass extends ASuperClass implements Serializable { + int num; + + private static final long serialVersionUID =6341246181948372513L; + ASubClass(int num, String name) { + super(name); + this.num = num; + } + + public String toString() { + return (super.toString() + "\nNum: " + num); + } +} diff --git a/test/jdk/java/io/FastSerializer/partialClassDesc/TestDescription.java b/test/jdk/java/io/FastSerializer/partialClassDesc/TestDescription.java new file mode 100644 index 000000000..05f634b51 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/partialClassDesc/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/partialClassDesc +*- @TestCaseName:partialClassDesc +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4373844 + * @summary Verify that partially initialized ObjectStreamClass instances + * cannot be obtained from ObjectStreamClass.lookup() in the event + * that the target class is uninitializable. + * @library /test/jdk/java/io/Serializable/partialClassDesc/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer PartialClassDesc + */ diff --git a/test/jdk/java/io/FastSerializer/primitiveClasses/TestDescription.java b/test/jdk/java/io/FastSerializer/primitiveClasses/TestDescription.java new file mode 100644 index 000000000..97a1bf169 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/primitiveClasses/TestDescription.java @@ -0,0 +1,20 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/primitiveClasses +*- @TestCaseName:primitiveClasses +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4171142 4519050 + * @summary Verify that primitive classes can be serialized and deserialized. + * @library /test/jdk/java/io/Serializable/primitiveClasses/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer PrimitiveClasses + */ diff --git a/test/jdk/java/io/FastSerializer/protocolVersion1/arrayVersion1.java b/test/jdk/java/io/FastSerializer/protocolVersion1/arrayVersion1.java new file mode 100644 index 000000000..f125c3053 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/protocolVersion1/arrayVersion1.java @@ -0,0 +1,68 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/arrayVersion1 +*- @TestCaseName:arrayVersion1 +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test serialize and deserialize of Array object +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true arrayVersion1 +*/ + + +import java.io.*; +import java.util.*; + + +public class arrayVersion1 { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo2.ser")); + oout.useProtocolVersion(ObjectInputStream.PROTOCOL_VERSION_1); + int num = 100; + Random r = new Random(); + int[] A1 = new int[num]; + int[] A2 = new int[num]; + int[] A3 = new int[num]; + int[] A4 = new int[num]; + for(int i = 0; i < num; i++) { + A1[i] = r.nextInt(); + A2[i] = r.nextInt(); + A3[i] = r.nextInt(); + A4[i] = r.nextInt(); + } + oout.writeObject(A1); + oout.writeObject(A2); + oout.writeObject(A3); + oout.writeObject(A4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo2.ser")); + int[] Aout1 = (int[])oin.readObject(); + int[] Aout2 = (int[])oin.readObject(); + int[] Aout3 = (int[])oin.readObject(); + int[] Aout4 = (int[])oin.readObject(); + oin.close(); + if(!Arrays.equals(A1,Aout1)||!Arrays.equals(A2,Aout2)||!Arrays.equals(A3,Aout3)||!Arrays.equals(A4,Aout4)){ + throw new Exception("deserialized Array different"); + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo2.ser")); + int[] Aout5 = (int[])oin2.readObject(); + int[] Aout6 = (int[])oin2.readObject(); + int[] Aout7 = (int[])oin2.readObject(); + int[] Aout8 = (int[])oin2.readObject(); + if(!Arrays.equals(A1,Aout5)||!Arrays.equals(A2,Aout6)||!Arrays.equals(A3,Aout7)||!Arrays.equals(A4,Aout8)){ + throw new Exception("deserialized Array different"); + } + oin2.close(); + } +} diff --git a/test/jdk/java/io/FastSerializer/protocolVersion1/enumVersion.java b/test/jdk/java/io/FastSerializer/protocolVersion1/enumVersion.java new file mode 100644 index 000000000..248a182ad --- /dev/null +++ b/test/jdk/java/io/FastSerializer/protocolVersion1/enumVersion.java @@ -0,0 +1,69 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/enumVersion +*- @TestCaseName:enumVersion +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test serialize and deserialize of Enum object +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true enumVersion +*/ + + +import java.io.*; +import java.util.*; + +enum E { + A, + B, + C, + D, + ; + } + +public class enumVersion { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo3.ser")); + oout.useProtocolVersion(ObjectInputStream.PROTOCOL_VERSION_1); + int num = 100; + Random r = new Random(); + E E1 = E.A; + E E2 = E.B; + E E3 = E.C; + E E4 = E.D; + oout.writeObject(E1); + oout.writeObject(E2); + oout.writeObject(E3); + oout.writeObject(E4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo3.ser")); + E Eout1 = (E)oin.readObject(); + E Eout2 = (E)oin.readObject(); + E Eout3 = (E)oin.readObject(); + E Eout4 = (E)oin.readObject(); + oin.close(); + if(!E1.equals(Eout1)||!E2.equals(Eout2)||!E3.equals(Eout3)||!E4.equals(Eout4)){ + throw new Exception("deserialized Enum different"); + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo3.ser")); + E Eout5 = (E)oin2.readObject(); + E Eout6 = (E)oin2.readObject(); + E Eout7 = (E)oin2.readObject(); + E Eout8 = (E)oin2.readObject(); + if(!E1.equals(Eout5)||!E2.equals(Eout6)||!E3.equals(Eout7)||!E4.equals(Eout8)){ + throw new Exception("deserialized Enum different"); + } + oin2.close(); + } +} diff --git a/test/jdk/java/io/FastSerializer/protocolVersion1/externVersion1.java b/test/jdk/java/io/FastSerializer/protocolVersion1/externVersion1.java new file mode 100644 index 000000000..40143a07a --- /dev/null +++ b/test/jdk/java/io/FastSerializer/protocolVersion1/externVersion1.java @@ -0,0 +1,96 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/externVersion1 +*- @TestCaseName:externVersion1 +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test change field to static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true externVersion1 +*/ + + +import java.io.*; + + +class Foo implements Externalizable { + int i ; + String s ; + public Foo(){} + Foo (int i, String s) { + this.i = i; + this.s = s; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s) ); + } +} + +public class externVersion1 { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.useProtocolVersion(ObjectInputStream.PROTOCOL_VERSION_1); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + }catch (StreamCorruptedException ex2){ + System.out.println("Expected Exception"); + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + }catch (StreamCorruptedException ex2){ + System.out.println("Expected Exception"); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/protocolVersion1/serVersion1.java b/test/jdk/java/io/FastSerializer/protocolVersion1/serVersion1.java new file mode 100644 index 000000000..17a9b8adf --- /dev/null +++ b/test/jdk/java/io/FastSerializer/protocolVersion1/serVersion1.java @@ -0,0 +1,66 @@ +/* +* @test +* @summary test change field to static on deserialize end +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true serVersion1 +*/ + + +import java.io.*; + + +class Foo implements Serializable { + Foo (int i, String s) { + this.i = i; + this.s = s; + } + static int i; + String s ; + + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s)); + } +} + +public class serVersion1 { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + String testsrc = System.getProperty("test.src"); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.useProtocolVersion(ObjectInputStream.PROTOCOL_VERSION_1); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/protocolVersion1/stringVersion1.java b/test/jdk/java/io/FastSerializer/protocolVersion1/stringVersion1.java new file mode 100644 index 000000000..a108ed7c8 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/protocolVersion1/stringVersion1.java @@ -0,0 +1,44 @@ +/* +* @test +* @summary test serialize and deserialize of String object +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true stringVersion1 +*/ + + +import java.io.*; + + +public class stringVersion1 { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo1.ser")); + oout.useProtocolVersion(ObjectInputStream.PROTOCOL_VERSION_1); + String sin1 = "Hello World1"; + String sin2 = "Hello World2"; + String sin3 = "Hello World3"; + String sin4 = "Hello World4"; + oout.writeObject(sin1); + oout.writeObject(sin2); + oout.writeObject(sin3); + oout.writeObject(sin4); + oout.close(); + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo1.ser")); + String sout1 = (String)oin.readObject(); + String sout2 = (String)oin.readObject(); + String sout3 = (String)oin.readObject(); + String sout4 = (String)oin.readObject(); + oin.close(); + if(!sout1.equals(sin1) || !sout2.equals(sin2) ||!sout3.equals(sin3) ||!sout4.equals(sin4)){ + throw new Exception("deserialized string different"); + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo1.ser")); + String sout5 = (String)oin2.readObject(); + String sout6 = (String)oin2.readObject(); + String sout7 = (String)oin2.readObject(); + String sout8 = (String)oin2.readObject(); + if(!sout5.equals(sin1) || !sout6.equals(sin2) ||!sout7.equals(sin3) ||!sout8.equals(sin4)){ + throw new Exception("deserialized string different"); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/proxy/TestDescription.java b/test/jdk/java/io/FastSerializer/proxy/TestDescription.java new file mode 100644 index 000000000..a8478395c --- /dev/null +++ b/test/jdk/java/io/FastSerializer/proxy/TestDescription.java @@ -0,0 +1,20 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/Basic +*- @TestCaseName:Basic +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @summary Verifies basic correct functioning of proxy serialization. + * @key randomness + * @library /test/jdk/java/io/Serializable/proxy/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Basic + */ diff --git a/test/jdk/java/io/FastSerializer/proxy/replace/TestDescription.java b/test/jdk/java/io/FastSerializer/proxy/replace/TestDescription.java new file mode 100644 index 000000000..287852ae3 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/proxy/replace/TestDescription.java @@ -0,0 +1,20 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/replace +*- @TestCaseName:replace +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @summary Ensure that serialization invokes writeReplace/readResolve methods + * on dynamic proxies, just as with normal objects. + * @library /test/jdk/java/io/Serializable/proxy/replace/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Test + */ diff --git a/test/jdk/java/io/FastSerializer/readPastObject/TestDescription.java b/test/jdk/java/io/FastSerializer/readPastObject/TestDescription.java new file mode 100644 index 000000000..c57c42a45 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/readPastObject/TestDescription.java @@ -0,0 +1,21 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/readPastObject +*- @TestCaseName:readPastObject +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4253271 + * @library /test/jdk/java/io/Serializable/readPastObject/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer ReadPastObject + * @summary Ensure that ObjectInputStream.readObject() is called, it doesn't + * read past the end of the object in the underlying stream. + */ diff --git a/test/jdk/java/io/FastSerializer/recursiveClassDescLookup/TestDescription.java b/test/jdk/java/io/FastSerializer/recursiveClassDescLookup/TestDescription.java new file mode 100644 index 000000000..d0395556b --- /dev/null +++ b/test/jdk/java/io/FastSerializer/recursiveClassDescLookup/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/recursiveClassDescLookup +*- @TestCaseName:recursiveClassDescLookup +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4803747 + * @library /test/jdk/java/io/Serializable/recursiveClassDescLookup/ + * @run main/othervm/timeout=20 -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Test + * @summary Verify that a nested call to ObjectStreamClass.lookup from within + * the static initializer of a serializable class will not cause + * deadlock. + */ diff --git a/test/jdk/java/io/FastSerializer/replaceStringArray/TestDescription.java b/test/jdk/java/io/FastSerializer/replaceStringArray/TestDescription.java new file mode 100644 index 000000000..cbeb05418 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/replaceStringArray/TestDescription.java @@ -0,0 +1,20 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/replaceStringArray +*- @TestCaseName:replaceStringArray +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4099013 + * @library /test/jdk/java/io/Serializable/replaceStringArray/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer ReplaceStringArray + * @summary Enable substitution of String and Array by ObjectStreams. + */ diff --git a/test/jdk/java/io/FastSerializer/replaceWithNull/TestDescription.java b/test/jdk/java/io/FastSerializer/replaceWithNull/TestDescription.java new file mode 100644 index 000000000..fe5b9610a --- /dev/null +++ b/test/jdk/java/io/FastSerializer/replaceWithNull/TestDescription.java @@ -0,0 +1,20 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/replaceWithNull +*- @TestCaseName:replaceWithNull +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4065313 + * @library /test/jdk/java/io/Serializable/replaceWithNull/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer ReplaceWithNull + * @summary Ensure that it is okay to replace an object with null. + */ diff --git a/test/jdk/java/io/FastSerializer/resolveClass/TestDescription.java b/test/jdk/java/io/FastSerializer/resolveClass/TestDescription.java new file mode 100644 index 000000000..e0ef76230 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/resolveClass/TestDescription.java @@ -0,0 +1,21 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/resolveClass +*- @TestCaseName:resolveClass +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4413434 + * @library /test/jdk/java/io/Serializable/resolveClass/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer MethodTest + * @summary Verify that generated java.lang.reflect implementation classes do + * not interfere with serialization's class resolution mechanism. + */ diff --git a/test/jdk/java/io/FastSerializer/resolveClass/consTest/Boot.java b/test/jdk/java/io/FastSerializer/resolveClass/consTest/Boot.java new file mode 100644 index 000000000..29229b268 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/resolveClass/consTest/Boot.java @@ -0,0 +1,15 @@ + +/* + * @bug 4413434 + * @summary Verify that generated java.lang.reflect implementation classes do + * not interfere with serialization's class resolution mechanism. + */ + +import java.io.*; + +// this class should be loaded from bootclasspath +public class Boot { + public Boot(ObjectInputStream oin) throws Exception { + oin.readObject(); + } +} diff --git a/test/jdk/java/io/FastSerializer/resolveClass/consTest/ConsTest.java b/test/jdk/java/io/FastSerializer/resolveClass/consTest/ConsTest.java new file mode 100644 index 000000000..3d3ef7004 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/resolveClass/consTest/ConsTest.java @@ -0,0 +1,36 @@ + + +/* + * @test + * @bug 4413434 + * @library /test/lib + * @build jdk.test.lib.util.JarUtils SetupJar Boot + * @run driver SetupJar + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -Xbootclasspath/a:boot.jar ConsTest + * @summary Verify that generated java.lang.reflect implementation classes do + * not interfere with serialization's class resolution mechanism. + */ + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.lang.reflect.Constructor; + +public class ConsTest implements Serializable { + public static void main(String[] args) throws Exception { + Constructor cons = Boot.class.getConstructor( + new Class[] { ObjectInputStream.class }); + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + ObjectOutputStream oout = new ObjectOutputStream(bout); + oout.writeObject(new ConsTest()); + oout.close(); + + for (int i = 0; i < 100; i++) { + ObjectInputStream oin = new ObjectInputStream( + new ByteArrayInputStream(bout.toByteArray())); + cons.newInstance(new Object[]{ oin }); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/resolveClass/consTest/SetupJar.java b/test/jdk/java/io/FastSerializer/resolveClass/consTest/SetupJar.java new file mode 100644 index 000000000..4e957863e --- /dev/null +++ b/test/jdk/java/io/FastSerializer/resolveClass/consTest/SetupJar.java @@ -0,0 +1,13 @@ + + +import java.nio.file.Path; +import java.nio.file.Paths; +import jdk.test.lib.util.JarUtils; +public class SetupJar { + + public static void main(String args[]) throws Exception { + Path classes = Paths.get(System.getProperty("test.classes", "")); + JarUtils.createJarFile(Paths.get("boot.jar"), classes, + classes.resolve("Boot.class")); + } +} diff --git a/test/jdk/java/io/FastSerializer/resolveClass/deserializeButton/DeserializeButtonTest.java b/test/jdk/java/io/FastSerializer/resolveClass/deserializeButton/DeserializeButtonTest.java new file mode 100644 index 000000000..5d17ab42d --- /dev/null +++ b/test/jdk/java/io/FastSerializer/resolveClass/deserializeButton/DeserializeButtonTest.java @@ -0,0 +1,50 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/DeserializeButtonTest +*- @TestCaseName:DeserializeButtonTest +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* + * @test + * @bug 4413434 + * @library /test/lib + * @build jdk.test.lib.util.JarUtils Foo + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer DeserializeButtonTest + * @summary Verify that class loaded outside of application class loader is + * correctly resolved during deserialization when read in by custom + * readObject() method of a bootstrap class (in this case, + * java.util.Vector). + */ + +import java.net.URLClassLoader; +import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; +import jdk.test.lib.util.JarUtils; +public class DeserializeButtonTest { + public static void main(String[] args) throws Exception { + setup(); + + try (URLClassLoader ldr = + new URLClassLoader(new URL[]{ new URL("file:cb.jar") })) { + Runnable r = (Runnable) Class.forName("Foo", true, ldr).newInstance(); + r.run(); + } + } + + private static void setup() throws Exception { + Path classes = Paths.get(System.getProperty("test.classes", "")); + JarUtils.createJarFile(Paths.get("cb.jar"), + classes, + classes.resolve("Foo.class"), + classes.resolve("Foo$TestElement.class")); + } +} diff --git a/test/jdk/java/io/FastSerializer/resolveClass/deserializeButton/Foo.java b/test/jdk/java/io/FastSerializer/resolveClass/deserializeButton/Foo.java new file mode 100644 index 000000000..b7525a9d0 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/resolveClass/deserializeButton/Foo.java @@ -0,0 +1,38 @@ + + +/* + * @bug 4413434 + * @summary Verify that class loaded outside of application class loader is + * correctly resolved during deserialization when read in by custom + * readObject() method of a bootstrap class (in this case, + * java.util.Vector). + */ + +import java.io.*; +import java.util.Vector; + +public class Foo implements Runnable { + + static class TestElement extends Object implements Serializable {} + + public void run() { + try { + Vector container = new Vector(); + container.add(new TestElement()); + + // iterate to trigger java.lang.reflect code generation + for (int i = 0; i < 100; i++) { + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + ObjectOutputStream oout = new ObjectOutputStream(bout); + oout.writeObject(container); + oout.close(); + ObjectInputStream oin = new ObjectInputStream( + new ByteArrayInputStream(bout.toByteArray())); + oin.readObject(); + } + } catch (Exception ex) { + throw new Error( + "Error occured while (de)serializing container: ", ex); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/resolveClassException/ResolveClassException.java b/test/jdk/java/io/FastSerializer/resolveClassException/ResolveClassException.java new file mode 100644 index 000000000..f37565d41 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/resolveClassException/ResolveClassException.java @@ -0,0 +1,75 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/ResolveClassException +*- @TestCaseName:ResolveClassException +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4191941 + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer ResolveClassException + * @summary Ensure that original ClassNotFoundException thrown inside of + * ObjectInputStream.resolveClass() is preserved (and thrown). + */ + +import java.io.*; + +class BrokenObjectInputStream extends ObjectInputStream { + + static final String message = "bodega"; + + BrokenObjectInputStream(InputStream in) throws IOException { + super(in); + } + + protected Class resolveClass(ObjectStreamClass desc) + throws IOException, ClassNotFoundException + { + throw new ClassNotFoundException(message); + } +} + +public class ResolveClassException { + public static void main(String[] args) throws Exception { + ByteArrayOutputStream bout; + ObjectOutputStream oout; + ByteArrayInputStream bin; + BrokenObjectInputStream oin; + Object obj; + + // write and read an object + obj = new Integer(5); + bout = new ByteArrayOutputStream(); + oout = new ObjectOutputStream(bout); + oout.writeObject(obj); + bin = new ByteArrayInputStream(bout.toByteArray()); + oin = new BrokenObjectInputStream(bin); + try { + oin.readObject(); + } catch (ClassNotFoundException e) { + if (! BrokenObjectInputStream.message.equals(e.getMessage())) + throw new Error("Original exception not preserved"); + } + + // write and read an array of objects + obj = new Integer[] { new Integer(5) }; + bout = new ByteArrayOutputStream(); + oout = new ObjectOutputStream(bout); + oout.writeObject(obj); + bin = new ByteArrayInputStream(bout.toByteArray()); + oin = new BrokenObjectInputStream(bin); + try { + oin.readObject(); + } catch (ClassNotFoundException e) { + if (! BrokenObjectInputStream.message.equals(e.getMessage())) + throw new Error("Original exception not preserved"); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/resolveClassException/TestDescription.java b/test/jdk/java/io/FastSerializer/resolveClassException/TestDescription.java new file mode 100644 index 000000000..028d66c5d --- /dev/null +++ b/test/jdk/java/io/FastSerializer/resolveClassException/TestDescription.java @@ -0,0 +1,21 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/ResolveClassException2 +*- @TestCaseName:ResolveClassException2 +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4191941 + * @library /test/jdk/java/io/Serializable/resolveClassException/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer ResolveClassException + * @summary Ensure that original ClassNotFoundException thrown inside of + * ObjectInputStream.resolveClass() is preserved (and thrown). + */ diff --git a/test/jdk/java/io/FastSerializer/resolveProxyClass/TestDescription.java b/test/jdk/java/io/FastSerializer/resolveProxyClass/TestDescription.java new file mode 100644 index 000000000..3597ff34f --- /dev/null +++ b/test/jdk/java/io/FastSerializer/resolveProxyClass/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/NonPublicInterface +*- @TestCaseName:NonPublicInterface +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4413817 8004928 + * @library /test/jdk/java/io/Serializable/resolveProxyClass/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer NonPublicInterface + * @summary Verify that ObjectInputStream.resolveProxyClass can properly + * resolve a dynamic proxy class which implements a non-public + * interface not defined in the latest user defined class loader. + */ diff --git a/test/jdk/java/io/FastSerializer/sanityCheck/TestDescription.java b/test/jdk/java/io/FastSerializer/sanityCheck/TestDescription.java new file mode 100644 index 000000000..4c0b3237b --- /dev/null +++ b/test/jdk/java/io/FastSerializer/sanityCheck/TestDescription.java @@ -0,0 +1,21 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/SanityCheck +*- @TestCaseName:SanityCheck +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @library /test/jdk/java/io/Serializable/sanityCheck/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer SanityCheck + * @summary Basic sanity check to test if default (de)serialization is + * transmitting values properly. + * @key randomness + */ diff --git a/test/jdk/java/io/FastSerializer/serialFilter/SerialFilterTest.java b/test/jdk/java/io/FastSerializer/serialFilter/SerialFilterTest.java new file mode 100644 index 000000000..23a0472b9 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/serialFilter/SerialFilterTest.java @@ -0,0 +1,848 @@ +/* + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* +*- @TestCaseID:jdk17/FastSerializer/SerialFilterTest +*- @TestCaseName:SerialFilterTest +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.EOFException; +import java.io.IOException; +import java.io.InvalidClassException; +import java.io.ObjectInputFilter; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serial; +import java.io.Serializable; +import java.lang.invoke.SerializedLambda; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.LongAdder; + +import javax.net.ssl.SSLEngineResult; + +import org.testng.Assert; +import org.testng.annotations.Test; +import org.testng.annotations.DataProvider; + +/* @test + * @bug 8234836 + * @build SerialFilterTest + * @run testng/othervm -Djdk.serialSetFilterAfterRead=true -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer SerialFilterTest + * + * @summary Test ObjectInputFilters using Builtin Filter Factory + */ +@Test +public class SerialFilterTest implements Serializable { + + @Serial + private static final long serialVersionUID = -6999613679881262446L; + + /** + * Enable three arg lambda. + * @param The pattern + * @param The test object + * @param Boolean for if the filter should allow or reject + */ + interface TriConsumer< T, U, V> { + void accept(T t, U u, V v); + } + + /** + * Misc object to use that should always be accepted. + */ + private static final Object otherObject = Integer.valueOf(0); + + + /** + * DataProvider for the individual patterns to test. + * Expand the patterns into cases for each of the Std and Compatibility APIs. + * @return an array of arrays of the parameters including factories + */ + @DataProvider(name="Patterns") + static Object[][] patterns() { + Object[][] patterns = new Object[][]{ + {"java.util.Hashtable"}, + {"java.util.Hash*"}, + {"javax.net.ssl.*"}, + {"javax.net.**"}, + {"*"}, + {"maxarray=47"}, + {"maxdepth=5"}, + {"maxrefs=10"}, + {"maxbytes=100"}, + {"maxbytes=72"}, + {"maxbytes=+1024"}, + {"java.base/java.util.Hashtable"}, + }; + return patterns; + } + + @DataProvider(name="InvalidPatterns") + static Object[][] invalidPatterns() { + return new Object [][] { + {".*"}, + {".**"}, + {"!"}, + {"/java.util.Hashtable"}, + {"java.base/"}, + {"/"}, + }; + } + + @DataProvider(name="Limits") + static Object[][] limits() { + // The numbers are arbitrary > 1 + return new Object[][] { + {"maxrefs", 1}, // 0 is tested as n-1 + {"maxrefs", 10}, + {"maxdepth", 5}, + {"maxbytes", 100}, + {"maxarray", 16}, + {"maxbytes", Long.MAX_VALUE}, + }; + } + + @DataProvider(name="InvalidLimits") + static Object[][] invalidLimits() { + return new Object[][] { + {"maxrefs=-1"}, + {"maxdepth=-1"}, + {"maxbytes=-1"}, + {"maxarray=-1"}, + {"xyz=0"}, + {"xyz=-1"}, + {"maxrefs=0xabc"}, + {"maxrefs=abc"}, + {"maxrefs="}, + {"maxrefs=+"}, + {"maxbytes=-1"}, + {"maxbytes=9223372036854775808"}, + {"maxbytes=-9223372036854775807"}, + }; + } + + /** + * DataProvider of individual objects. Used to check the information + * available to the filter. + * @return Arrays of parameters with objects + */ + @DataProvider(name="Objects") + static Object[][] objects() { + byte[] byteArray = new byte[0]; + Object[] objArray = new Object[7]; + objArray[objArray.length - 1] = objArray; + + Class serClass = null; + String className = "java.util.concurrent.atomic.LongAdder$SerializationProxy"; + try { + serClass = Class.forName(className); + } catch (Exception e) { + Assert.fail("missing class: " + className, e); + } + + Class[] interfaces = {Runnable.class}; + Runnable proxy = (Runnable) Proxy.newProxyInstance(null, + interfaces, (p, m, args) -> p); + + Runnable runnable = (Runnable & Serializable) SerialFilterTest::noop; + + List> classList = new ArrayList<>(); + classList.add(HashSet.class); + classList.addAll(Collections.nCopies(21, Map.Entry[].class)); + + Object[][] objects = { + { null, 0, -1, 0, 0, 0, + Arrays.asList()}, // no callback, no values + { objArray, 3, 7, 9, 2, 43, + Arrays.asList(objArray.getClass(), objArray.getClass())}, + { Object[].class, 1, -1, 1, 1, 27, + Arrays.asList(Object[].class)}, + { new SerialFilterTest(), 1, -1, 1, 1, 24, + Arrays.asList(SerialFilterTest.class)}, + { new LongAdder(), 2, -1, 2, 1, 73, + Arrays.asList(serClass, LongAdder.class)}, + { new byte[14], 2, 14, 2, 1, 15, + Arrays.asList(byteArray.getClass(), byteArray.getClass())}, + { runnable, 7, 0, 13, 2, 164, + Arrays.asList(java.lang.invoke.SerializedLambda.class, + objArray.getClass(), + objArray.getClass(), + SerialFilterTest.class, + java.lang.invoke.SerializedLambda.class)}, + { deepHashSet(10), 69, 4, 50, 11, 607, classList }, + { proxy.getClass(), 3, -1, 2, 2, 57, + Arrays.asList(Runnable.class, + java.lang.reflect.Proxy.class, + java.lang.reflect.Proxy.class)}, + { new F(), 6, -1, 6, 6, 27, + Arrays.asList(F.class, E.class, D.class, + C.class, B.class, A.class)}, + + }; + return objects; + } + + @DataProvider(name="Arrays") + static Object[][] arrays() { + return new Object[][]{ + {new Object[16], 16}, + {new boolean[16], 16}, + {new byte[16], 16}, + {new char[16], 16}, + {new int[16], 16}, + {new long[16], 16}, + {new short[16], 16}, + {new float[16], 16}, + {new double[16], 16}, + }; + } + + + /** + * Test each object and verify the classes identified by the filter, + * the count of calls to the filter, the max array size, max refs, max depth, + * max bytes. + * This test ignores/is not dependent on the global filter settings. + * + * @param object a Serializable object + * @param count the expected count of calls to the filter + * @param maxArray the maximum array size + * @param maxRefs the maximum references + * @param maxDepth the maximum depth + * @param maxBytes the maximum stream size + * @param classes the expected (unique) classes + * @throws IOException + */ + @Test(dataProvider="Objects") + void t1(Object object, + long count, long maxArray, long maxRefs, long maxDepth, long maxBytes, + List> classes) throws IOException { + byte[] bytes = writeObjects(object); + Validator validator = new Validator(); + validate(bytes, validator); + System.out.printf("v: %s%n", validator); + + Assert.assertEquals(validator.count, count, "callback count wrong"); + Assert.assertEquals(validator.classes, classes, "classes mismatch"); + Assert.assertEquals(validator.maxArray, maxArray, "maxArray mismatch"); + Assert.assertEquals(validator.maxRefs, maxRefs, "maxRefs wrong"); + Assert.assertEquals(validator.maxDepth, maxDepth, "depth wrong"); + Assert.assertEquals(validator.maxBytes, maxBytes, "maxBytes wrong"); + } + + /** + * Test each pattern with an appropriate object. + * A filter is created from the pattern and used to serialize and + * deserialize a generated object with both the positive and negative case. + * This test ignores/is not dependent on the global filter settings. + * + * @param pattern a pattern + */ + @Test(dataProvider="Patterns") + void testPatterns(String pattern) { + evalPattern(pattern, (p, o, neg) -> testPatterns(p, o, neg)); + } + + /** + * Test that the filter on a OIS can be set only on a fresh OIS, + * before deserializing any objects. + * This test is agnostic the global filter being set or not. + */ + @Test + void nonResettableFilter() { + Validator validator1 = new Validator(); + Validator validator2 = new Validator(); + + Validator[] filterCases = { + validator1, // setting filter to a non-null filter + null, // setting stream-specific filter to null + }; + + for (Validator validator : filterCases) { + try { + byte[] bytes = writeObjects("text1"); // an object + + try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais)) { + // Check the initial filter is the global filter; may be null + ObjectInputFilter global = ObjectInputFilter.Config.getSerialFilter(); + ObjectInputFilter initial = ois.getObjectInputFilter(); + Assert.assertEquals(global, initial, "initial filter should be the global filter"); + + ois.setObjectInputFilter(validator); + Object o = ois.readObject(); + try { + ois.setObjectInputFilter(validator2); + Assert.fail("Should not be able to set filter twice"); + } catch (IllegalStateException ise) { + // success, the exception was expected + } + } catch (EOFException eof) { + Assert.fail("Should not reach end-of-file", eof); + } catch (ClassNotFoundException cnf) { + Assert.fail("Deserializing", cnf); + } + } catch (IOException ex) { + Assert.fail("Unexpected IOException", ex); + } + } + } + + + /** + * Test that if an Objects readReadResolve method returns an array + * that the callback to the filter includes the proper array length. + * @throws IOException if an error occurs + */ + @Test(dataProvider="Arrays") + void testReadResolveToArray(Object array, int length) throws IOException { + ReadResolveToArray object = new ReadResolveToArray(array, length); + byte[] bytes = writeObjects(object); + Object o = validate(bytes, object); // the object is its own filter + Assert.assertEquals(o.getClass(), array.getClass(), "Filter not called with the array"); + } + + + /** + * Test repeated limits use the last value. + * Construct a filter with the limit and the limit repeated -1. + * Invoke the filter with the limit to make sure it is rejected. + * Invoke the filter with the limit -1 to make sure it is accepted. + * @param name the name of the limit to test + * @param value a test value + */ + @Test(dataProvider="Limits") + void testLimits(String name, long value) { + Class arrayClass = new int[0].getClass(); + String pattern = String.format("%s=%d;%s=%d", name, value, name, value - 1); + ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern); + Assert.assertEquals( + filter.checkInput(new FilterValues(arrayClass, value, value, value, value)), + ObjectInputFilter.Status.REJECTED, + "last limit value not used: " + filter); + Assert.assertEquals( + filter.checkInput(new FilterValues(arrayClass, value-1, value-1, value-1, value-1)), + ObjectInputFilter.Status.UNDECIDED, + "last limit value not used: " + filter); + } + + /** + * Test invalid limits. + * Construct a filter with the limit, it should throw IllegalArgumentException. + * @param pattern a pattern to test + */ + @Test(dataProvider="InvalidLimits", expectedExceptions=java.lang.IllegalArgumentException.class) + void testInvalidLimits(String pattern) { + try { + ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern); + } catch (IllegalArgumentException iae) { + System.out.printf(" success exception: %s%n", iae); + throw iae; + } + } + + /** + * Test that returning null from a filter causes deserialization to fail. + */ + @Test(expectedExceptions=InvalidClassException.class) + void testNullStatus() throws IOException { + byte[] bytes = writeObjects(0); // an Integer + try { + Object o = validate(bytes, new ObjectInputFilter() { + public ObjectInputFilter.Status checkInput(ObjectInputFilter.FilterInfo f) { + return null; + } + }); + } catch (InvalidClassException ice) { + System.out.printf(" success exception: %s%n", ice); + throw ice; + } + } + + /** + * Verify that malformed patterns throw IAE. + * @param pattern pattern from the data source + */ + @Test(dataProvider="InvalidPatterns", expectedExceptions=IllegalArgumentException.class) + void testInvalidPatterns(String pattern) { + try { + ObjectInputFilter.Config.createFilter(pattern); + } catch (IllegalArgumentException iae) { + System.out.printf(" success exception: %s%n", iae); + throw iae; + } + } + + /** + * Test that Config.create returns null if the argument does not contain any patterns or limits. + */ + @Test() + void testEmptyPattern() { + ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(""); + Assert.assertNull(filter, "empty pattern did not return null"); + + filter = ObjectInputFilter.Config.createFilter(";;;;"); + Assert.assertNull(filter, "pattern with only delimiters did not return null"); + } + + /** + * Read objects from the serialized stream, validated with the filter. + * + * @param bytes a byte array to read objects from + * @param filter the ObjectInputFilter + * @return the object deserialized if any + * @throws IOException can be thrown + */ + static Object validate(byte[] bytes, + ObjectInputFilter filter) throws IOException { + try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + ObjectInputStream ois = new ObjectInputStream(bais)) { + ois.setObjectInputFilter(filter); + + Object o = ois.readObject(); + return o; + } catch (EOFException eof) { + // normal completion + } catch (ClassNotFoundException cnf) { + Assert.fail("Deserializing", cnf); + } + return null; + } + + /** + * Write objects and return a byte array with the bytes. + * + * @param objects zero or more objects to serialize + * @return the byte array of the serialized objects + * @throws IOException if an exception occurs + */ + static byte[] writeObjects(Object... objects) throws IOException { + byte[] bytes; + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos)) { + for (Object o : objects) { + oos.writeObject(o); + } + bytes = baos.toByteArray(); + } + return bytes; + } + + /** + * A filter that accumulates information about the checkInput callbacks + * that can be checked after readObject completes. + */ + static class Validator implements ObjectInputFilter { + long count; // Count of calls to checkInput + List> classes = new ArrayList<>(); + long maxArray = -1; + long maxRefs; + long maxDepth; + long maxBytes; + + Validator() { + } + + @Override + public ObjectInputFilter.Status checkInput(FilterInfo filter) { + Class serialClass = filter.serialClass(); + System.out.printf(" checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n", + serialClass, filter.arrayLength(), filter.references(), + filter.depth(), filter.streamBytes()); + count++; + if (serialClass != null) { + if (serialClass.getName().contains("$$Lambda$")) { + // TBD: proper identification of serialized Lambdas? + // Fold the serialized Lambda into the SerializedLambda type + classes.add(SerializedLambda.class); + } else if (Proxy.isProxyClass(serialClass)) { + classes.add(Proxy.class); + } else { + classes.add(serialClass); + } + + } + this.maxArray = Math.max(this.maxArray, filter.arrayLength()); + this.maxRefs = Math.max(this.maxRefs, filter.references()); + this.maxDepth = Math.max(this.maxDepth, filter.depth()); + this.maxBytes = Math.max(this.maxBytes, filter.streamBytes()); + return ObjectInputFilter.Status.UNDECIDED; + } + + public String toString(){ + return "count: " + count + + ", classes: " + classes.toString() + + ", maxArray: " + maxArray + + ", maxRefs: " + maxRefs + + ", maxDepth: " + maxDepth + + ", maxBytes: " + maxBytes; + } + } + + + /** + * Create a filter from a pattern and API factory, then serialize and + * deserialize an object and check allowed or reject. + * + * @param pattern the pattern + * @param object the test object + * @param allowed the expected result from ObjectInputStream (exception or not) + */ + static void testPatterns(String pattern, Object object, boolean allowed) { + try { + byte[] bytes = SerialFilterTest.writeObjects(object); + ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern); + validate(bytes, filter); + Assert.assertTrue(allowed, "filter should have thrown an exception"); + } catch (IllegalArgumentException iae) { + Assert.fail("bad format pattern", iae); + } catch (InvalidClassException ice) { + Assert.assertFalse(allowed, "filter should not have thrown an exception: " + ice); + } catch (IOException ioe) { + Assert.fail("Unexpected IOException", ioe); + } + } + + /** + * For a filter pattern, generate and apply a test object to the action. + * @param pattern a pattern + * @param action an action to perform on positive and negative cases + */ + static void evalPattern(String pattern, TriConsumer action) { + Object o = genTestObject(pattern, true); + Assert.assertNotNull(o, "success generation failed"); + action.accept(pattern, o, true); + + // Test the negative pattern + o = genTestObject(pattern, false); + Assert.assertNotNull(o, "fail generation failed"); + String negPattern = pattern.contains("=") ? pattern : "!" + pattern; + action.accept(negPattern, o, false); + } + + /** + * Generate a test object based on the pattern. + * Handles each of the forms of the pattern, wildcards, + * class name, various limit forms. + * @param pattern a pattern + * @param allowed a boolean indicating to generate the allowed or disallowed case + * @return an object or {@code null} to indicate no suitable object could be generated + */ + static Object genTestObject(String pattern, boolean allowed) { + if (pattern.contains("=")) { + return genTestLimit(pattern, allowed); + } else if (pattern.endsWith("*")) { + return genTestObjectWildcard(pattern, allowed); + } else { + // class + // isolate module name, if any + int poffset = 0; + int soffset = pattern.indexOf('/', poffset); + String module = null; + if (soffset >= 0) { + poffset = soffset + 1; + module = pattern.substring(0, soffset); + } + try { + Class clazz = Class.forName(pattern.substring(poffset)); + Constructor cons = clazz.getConstructor(); + return cons.newInstance(); + } catch (ClassNotFoundException ex) { + Assert.fail("no such class available: " + pattern); + } catch (InvocationTargetException + | NoSuchMethodException + | InstantiationException + | IllegalAccessException ex1) { + Assert.fail("newInstance: " + ex1); + } + } + return null; + } + + /** + * Generate an object to be used with the various wildcard pattern forms. + * Explicitly supports only specific package wildcards with specific objects. + * @param pattern a wildcard pattern ending in "*" + * @param allowed a boolean indicating to generate the allowed or disallowed case + * @return an object within or outside the wildcard + */ + static Object genTestObjectWildcard(String pattern, boolean allowed) { + if (pattern.endsWith(".**")) { + // package hierarchy wildcard + if (pattern.startsWith("javax.net.")) { + return SSLEngineResult.Status.BUFFER_OVERFLOW; + } + if (pattern.startsWith("java.")) { + return 4; + } + if (pattern.startsWith("javax.")) { + return SSLEngineResult.Status.BUFFER_UNDERFLOW; + } + return otherObject; + } else if (pattern.endsWith(".*")) { + // package wildcard + if (pattern.startsWith("javax.net.ssl")) { + return SSLEngineResult.Status.BUFFER_UNDERFLOW; + } + } else { + // class wildcard + if (pattern.equals("*")) { + return otherObject; // any object will do + } + if (pattern.startsWith("java.util.Hash")) { + return new Hashtable(); + } + } + Assert.fail("Object could not be generated for pattern: " + + pattern + + ", allowed: " + allowed); + return null; + } + + /** + * Generate a limit test object for the pattern. + * For positive cases, the object exactly hits the limit. + * For negative cases, the object is 1 greater than the limit + * @param pattern the pattern, containing "=" and a maxXXX keyword + * @param allowed a boolean indicating to generate the allowed or disallowed case + * @return a sitable object + */ + static Object genTestLimit(String pattern, boolean allowed) { + int ndx = pattern.indexOf('='); + Assert.assertNotEquals(ndx, -1, "missing value in limit"); + long value = Long.parseUnsignedLong(pattern.substring(ndx+1)); + if (pattern.startsWith("maxdepth=")) { + // Return an object with the requested depth (or 1 greater) + long depth = allowed ? value : value + 1; + Object[] array = new Object[1]; + for (int i = 1; i < depth; i++) { + Object[] n = new Object[1]; + n[0] = array; + array = n; + } + return array; + } else if (pattern.startsWith("maxbytes=")) { + // Return a byte array that when written to OOS creates + // a stream of exactly the size requested. + return genMaxBytesObject(allowed, value); + } else if (pattern.startsWith("maxrefs=")) { + // 4 references to classes in addition to the array contents + Object[] array = new Object[allowed ? (int)value - 4 : (int)value - 3]; + for (int i = 0; i < array.length; i++) { + array[i] = otherObject; + } + return array; + } else if (pattern.startsWith("maxarray=")) { + return allowed ? new int[(int)value] : new int[(int)value+1]; + } + Assert.fail("Object could not be generated for pattern: " + + pattern + + ", allowed: " + allowed); + return null; + } + + /** + * Generate an an object that will be serialized to some number of bytes. + * Or 1 greater if allowed is false. + * It returns a two element Object array holding a byte array sized + * to achieve the desired total size. + * @param allowed true if the stream should be allowed at that size, + * false if the stream should be larger + * @param maxBytes the number of bytes desired in the stream; + * should not be less than 72 (due to protocol overhead). + * @return a object that will be serialized to the length requested + */ + private static Object genMaxBytesObject(boolean allowed, long maxBytes) { + Object[] holder = new Object[2]; + long desiredSize = allowed ? maxBytes : maxBytes + 1; + long actualSize = desiredSize; + long byteSize = desiredSize - 72; // estimate needed array size + do { + byteSize += (desiredSize - actualSize); + byte[] a = new byte[(int)byteSize]; + holder[0] = a; + holder[1] = a; + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream os = new ObjectOutputStream(baos)) { + os.writeObject(holder); + os.flush(); + actualSize = baos.size(); + } catch (IOException ie) { + Assert.fail("exception generating stream", ie); + } + } while (actualSize != desiredSize); + return holder; + } + + /** + * Returns a HashSet of a requested depth. + * @param depth the depth + * @return a HashSet of HashSets... + */ + static HashSet deepHashSet(int depth) { + HashSet hashSet = new HashSet<>(); + HashSet s1 = hashSet; + HashSet s2 = new HashSet<>(); + for (int i = 0; i < depth; i++ ) { + HashSet t1 = new HashSet<>(); + HashSet t2 = new HashSet<>(); + // make t1 not equal to t2 + t1.add("by Jimminy"); + s1.add(t1); + s1.add(t2); + s2.add(t1); + s2.add(t2); + s1 = t1; + s2 = t2; + } + return hashSet; + } + + /** + * Simple method to use with Serialized Lambda. + */ + private static void noop() {} + + + /** + * Class that returns an array from readResolve and also implements + * the ObjectInputFilter to check that it has the expected length. + */ + static class ReadResolveToArray implements Serializable, ObjectInputFilter { + @Serial + private static final long serialVersionUID = 123456789L; + + @SuppressWarnings("serial") /* Incorrect declarations are being tested */ + private final Object array; + private final int length; + + ReadResolveToArray(Object array, int length) { + this.array = array; + this.length = length; + } + + @Serial + Object readResolve() { + return array; + } + + @Override + public ObjectInputFilter.Status checkInput(FilterInfo filter) { + if (ReadResolveToArray.class.isAssignableFrom(filter.serialClass())) { + return ObjectInputFilter.Status.ALLOWED; + } + if (filter.serialClass() != array.getClass() || + (filter.arrayLength() >= 0 && filter.arrayLength() != length)) { + return ObjectInputFilter.Status.REJECTED; + } + return ObjectInputFilter.Status.UNDECIDED; + } + + } + + /** + * Hold a snapshot of values to be passed to an ObjectInputFilter. + */ + static class FilterValues implements ObjectInputFilter.FilterInfo { + private final Class clazz; + private final long arrayLength; + private final long depth; + private final long references; + private final long streamBytes; + + public FilterValues(Class clazz, long arrayLength, long depth, long references, long streamBytes) { + this.clazz = clazz; + this.arrayLength = arrayLength; + this.depth = depth; + this.references = references; + this.streamBytes = streamBytes; + } + + @Override + public Class serialClass() { + return clazz; + } + + public long arrayLength() { + return arrayLength; + } + + public long depth() { + return depth; + } + + public long references() { + return references; + } + + public long streamBytes() { + return streamBytes; + } + } + + // Deeper superclass hierarchy + static class A implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + }; + static class B extends A { + @Serial + private static final long serialVersionUID = 2L; + } + static class C extends B { + @Serial + private static final long serialVersionUID = 3L; + } + static class D extends C { + @Serial + private static final long serialVersionUID = 4L; + } + static class E extends D { + @Serial + private static final long serialVersionUID = 5L; + } + static class F extends E { + @Serial + private static final long serialVersionUID = 6L; + } + +} diff --git a/test/jdk/java/io/FastSerializer/serialFilter/TestDescription.java b/test/jdk/java/io/FastSerializer/serialFilter/TestDescription.java new file mode 100644 index 000000000..837652128 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/serialFilter/TestDescription.java @@ -0,0 +1,84 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/CheckArrayTest +*- @TestCaseName:CheckArrayTest +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @library /test/jdk/java/io/Serializable/serialFilter/ + * @build CheckArrayTest SerialFilterTest + * @bug 8203368 + * @modules java.base/jdk.internal.access + * @run testng/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer CheckArrayTest + * + * @summary Test the SharedSecret access to ObjectInputStream.checkArray works + * with overridden subclasses. + */ + +/* @test + * @library /test/jdk/java/io/Serializable/serialFilter/ + * @build FilterWithSecurityManagerTest SerialFilterTest + * @run testng/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer FilterWithSecurityManagerTest + * @run testng/othervm/policy=security.policy.without.globalFilter + * -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer + * -Djava.security.manager=default FilterWithSecurityManagerTest + * @run testng/othervm/policy=security.policy + * -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer + * -Djava.security.manager=default + * -Djdk.serialFilter=java.lang.Integer FilterWithSecurityManagerTest + * + * @summary Test that setting specific filter is checked by security manager, + * setting process-wide filter is checked by security manager. + */ + + +/* @test + * @library /test/jdk/java/io/Serializable/serialFilter/ + * @build MixedFiltersTest SerialFilterTest + * @run testng/othervm + * -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer + * -Djdk.serialFilter=!java.**;!java.lang.Long;maxdepth=5;maxarray=5;maxbytes=90;maxrefs=5 MixedFiltersTest + * @run testng/othervm + * -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer + * -Djdk.serialFilter=java.**;java.lang.Long;maxdepth=1000;maxarray=1000;maxbytes=1000;maxrefs=1000 MixedFiltersTest + * + * @summary Test that when both global filter and specific filter are set, + * global filter will not affect specific filter. + */ + +/* @test + * @library /test/jdk/java/io/Serializable/serialFilter/ + * @build CheckInputOrderTest SerialFilterTest + * @run testng/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer CheckInputOrderTest + * + * @summary Test that when both global filter and specific filter are set, + * global filter will not affect specific filter. + */ + +/* @test + * @bug 8231422 + * @library /test/jdk/java/io/Serializable/serialFilter/ + * @build GlobalFilterTest SerialFilterTest + * @run testng/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer GlobalFilterTest + * @run testng/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer + * -Djdk.serialFilter=java.** + * -Dexpected-jdk.serialFilter=java.** GlobalFilterTest + * @run testng/othervm/policy=security.policy + * -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer GlobalFilterTest + * @run testng/othervm/policy=security.policy + * -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer + * -Djava.security.properties=${test.src}/java.security-extra1 + * -Djava.security.debug=properties GlobalFilterTest + * + * @summary Test Global Filters + */ + + diff --git a/test/jdk/java/io/FastSerializer/serialFilter/java.security-extra1 b/test/jdk/java/io/FastSerializer/serialFilter/java.security-extra1 new file mode 100644 index 000000000..7a52040c6 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/serialFilter/java.security-extra1 @@ -0,0 +1,4 @@ +# Serialization Input Process-wide Filter +# See conf/security/java.security for pattern synatx +# +jdk.serialFilter=java.**;javax.**;maxarray=34;maxdepth=7 diff --git a/test/jdk/java/io/FastSerializer/serialFilter/security.policy b/test/jdk/java/io/FastSerializer/serialFilter/security.policy new file mode 100644 index 000000000..7362da3af --- /dev/null +++ b/test/jdk/java/io/FastSerializer/serialFilter/security.policy @@ -0,0 +1,13 @@ +// Individual Permissions to for GlobalFilterTest and FilterWithSecurityManager +grant { + // Specific permission under test + permission java.io.SerializablePermission "serialFilter"; + + // Permissions needed to run the test + permission java.util.PropertyPermission "*", "read,write"; + permission java.io.FilePermission "<>", "read,write,delete"; + permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; + permission java.security.SecurityPermission "*"; + permission java.lang.RuntimePermission "accessDeclaredMembers"; +}; + diff --git a/test/jdk/java/io/FastSerializer/serialFilter/security.policy.without.globalFilter b/test/jdk/java/io/FastSerializer/serialFilter/security.policy.without.globalFilter new file mode 100644 index 000000000..0e98d6981 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/serialFilter/security.policy.without.globalFilter @@ -0,0 +1,9 @@ +// Individual Permissions for FilterWithSecurityManagerTest +grant { + // Permissions needed to run the test + permission java.util.PropertyPermission "*", "read"; + permission java.io.FilePermission "<>", "read,write,delete"; + permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; + permission java.lang.RuntimePermission "accessDeclaredMembers"; +}; + diff --git a/test/jdk/java/io/FastSerializer/serialver/classpath/ClasspathTest.java b/test/jdk/java/io/FastSerializer/serialver/classpath/ClasspathTest.java new file mode 100644 index 000000000..727cae8b5 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/serialver/classpath/ClasspathTest.java @@ -0,0 +1,54 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/ClasspathTest +*- @TestCaseName:ClasspathTest +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* + * @test + * @bug 4035147 4785472 + * @library /test/lib + * @build jdk.test.lib.Utils + * @build jdk.test.lib.Asserts + * @build jdk.test.lib.JDKToolFinder + * @build jdk.test.lib.JDKToolLauncher + * @build jdk.test.lib.Platform + * @build jdk.test.lib.process.* + * @build ClasspathTest + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer serialver.ClasspathTest + * @summary Test the use of the -classpath switch in the serialver application. + */ + +package serialver; + +import java.io.File; + +import jdk.test.lib.JDKToolLauncher; +import jdk.test.lib.process.ProcessTools; + +public class ClasspathTest implements java.io.Serializable { + int a; + int b; + + public static void main(String args[]) throws Exception { + JDKToolLauncher serialver = + JDKToolLauncher.create("serialver") + .addToolArg("-classpath") + .addToolArg(System.getProperty("test.class.path")) + .addToolArg("serialver.ClasspathTest"); + Process p = ProcessTools.startProcess("serialver", + new ProcessBuilder(serialver.getCommand())); + p.waitFor(); + if (p.exitValue() != 0) { + throw new RuntimeException("error occurs in serialver"); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/serialver/nested/NestedTest.java b/test/jdk/java/io/FastSerializer/serialver/nested/NestedTest.java new file mode 100644 index 000000000..3292ff431 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/serialver/nested/NestedTest.java @@ -0,0 +1,58 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/NestedTest +*- @TestCaseName:NestedTest +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* + * @test + * @bug 4312217 4785473 + * @library /test/lib + * @build jdk.test.lib.Utils + * jdk.test.lib.Asserts + * jdk.test.lib.JDKToolFinder + * jdk.test.lib.JDKToolLauncher + * jdk.test.lib.Platform + * jdk.test.lib.process.* + * @build NestedTest + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer serialver.NestedTest + * @summary To test the use of nested class specification using the '.' + * notation instead of the '$' notation. + */ + +package serialver; + +import java.io.Serializable; + +import jdk.test.lib.JDKToolLauncher; +import jdk.test.lib.process.ProcessTools; + +public class NestedTest implements Serializable { + public static class Test1 implements Serializable { + public static class Test2 implements Serializable{ + private static final long serialVersionUID = 100L; + } + } + + public static void main(String args[]) throws Exception { + JDKToolLauncher serialver = + JDKToolLauncher.create("serialver") + .addToolArg("-classpath") + .addToolArg(System.getProperty("test.class.path")) + .addToolArg("serialver.NestedTest.Test1.Test2"); + Process p = ProcessTools.startProcess("serialver", + new ProcessBuilder(serialver.getCommand())); + p.waitFor(); + if (p.exitValue() != 0) { + throw new RuntimeException("error occurs in serialver."); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/skipToEndOfBlockData/TestDescription.java b/test/jdk/java/io/FastSerializer/skipToEndOfBlockData/TestDescription.java new file mode 100644 index 000000000..0fb7b9b80 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/skipToEndOfBlockData/TestDescription.java @@ -0,0 +1,23 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/skipToEndOfBlockData +*- @TestCaseName:skipToEndOfBlockData +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4228592 + * @library /test/jdk/java/io/Serializable/skipToEndOfBlockData/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer SkipToEndOfBlockData + * @summary Ensure that ObjectInputStream properly skips over block data when a + * class that defines readObject() or readExternal() fails to read all + * of the data written by the corresponding writeObject() or + * writeExternal() method. + */ diff --git a/test/jdk/java/io/FastSerializer/skippedObjCNFException/TestDescription.java b/test/jdk/java/io/FastSerializer/skippedObjCNFException/TestDescription.java new file mode 100644 index 000000000..1db6ad1ad --- /dev/null +++ b/test/jdk/java/io/FastSerializer/skippedObjCNFException/TestDescription.java @@ -0,0 +1,29 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/skippedObjCNFException +*- @TestCaseName:skippedObjCNFException +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4313167 + * + * @library /test/jdk/java/io/Serializable/skippedObjCNFException/ + * @clean Write Read A B C + * @build Write + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Write + * @clean Write Read A B C + * @build Read + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Read + * + * @summary Verify that ClassNotFoundExceptions caused by values referenced + * (perhaps transitively) by "skipped" fields will not cause + * deserialization failure. + */ diff --git a/test/jdk/java/io/FastSerializer/stopCustomDeserialization/TestDescription.java b/test/jdk/java/io/FastSerializer/stopCustomDeserialization/TestDescription.java new file mode 100644 index 000000000..815605fdc --- /dev/null +++ b/test/jdk/java/io/FastSerializer/stopCustomDeserialization/TestDescription.java @@ -0,0 +1,29 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/stopCustomDeserialization +*- @TestCaseName:stopCustomDeserialization +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4663191 + * @summary Verify that readObject and readObjectNoData methods will not be + * called on an object being deserialized if that object is already + * tagged with a ClassNotFoundException. + * + * @library /test/jdk/java/io/Serializable/stopCustomDeserialization/ + * /test/jdk/java/io/FastSerializer/util/ + * @run driver CleanActualClass Write.class Read.class A.class B.class C.class X.class + * @build Write + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Write + * @run driver CleanActualClass Write.class Read.class A.class B.class C.class X.class + * @build Read + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Read + */ diff --git a/test/jdk/java/io/FastSerializer/subclass/Allow.policy b/test/jdk/java/io/FastSerializer/subclass/Allow.policy new file mode 100644 index 000000000..a31cebf49 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/subclass/Allow.policy @@ -0,0 +1,9 @@ +grant { + // "standard" properies that can be read by anyone + permission java.io.FilePermission "-","read,write,execute"; + permission java.io.SerializablePermission "enableSubstitution"; + + // Needed to get access to private writeObjectMethod and + // to be able to call it. + permission java.lang.reflect.ReflectPermission "access"; +}; diff --git a/test/jdk/java/io/FastSerializer/subclass/TestDescription.java b/test/jdk/java/io/FastSerializer/subclass/TestDescription.java new file mode 100644 index 000000000..069032fbd --- /dev/null +++ b/test/jdk/java/io/FastSerializer/subclass/TestDescription.java @@ -0,0 +1,38 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/subclass +*- @TestCaseName:subclass +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* + * @test + * @bug 4100915 + * @summary Verify that [write/read]ObjectOverride methods get called. + * Test verifies that ALL methods to write an object can + * be overridden. However, the testing for reading an object + * is incomplete. Only test that readObjectOverride is called. + * An entire protocol would need to be implemented and written + * out before being able to test the input side of the API. + * + * Also, would be appropriate that this program verify + * that if SerializablePermission "enableSubclassImplementation" + * is not in the security policy and security is enabled, that + * a security exception is thrown when constructing the + * ObjectOutputStream subclass. + * + * + * @library /test/jdk/java/io/Serializable/subclass/ + * @build AbstractObjectInputStream AbstractObjectOutputStream + * @build XObjectInputStream XObjectOutputStream + * @build SubclassTest + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer SubclassTest + * @run main/othervm/policy=Allow.policy -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer SubclassTest -expectSecurityException + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/subclassGC/SubclassOfOOS.java b/test/jdk/java/io/FastSerializer/subclassGC/SubclassOfOOS.java new file mode 100644 index 000000000..e19c12f76 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/subclassGC/SubclassOfOOS.java @@ -0,0 +1,13 @@ + + +import java.io.*; + +public class SubclassOfOOS extends ObjectOutputStream { + public SubclassOfOOS(OutputStream os) throws IOException { + super(os); + } + + public SubclassOfOOS() throws IOException { + super(); + } +} diff --git a/test/jdk/java/io/FastSerializer/subclassGC/TestDescription.java b/test/jdk/java/io/FastSerializer/subclassGC/TestDescription.java new file mode 100644 index 000000000..28e3aff80 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/subclassGC/TestDescription.java @@ -0,0 +1,26 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/subclassGC +*- @TestCaseName:subclassGC +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 6232010 + * @summary this test checks that replacing SoftCache class with ConcurrentMap + * in ObjectInputStream/ObjectOutputStream gives an opportunity to + * classes which are inherited from OIS and OOS and loaded through + * separete ClassLoaders be available for garbage collection + * + * @author Andrey Ozerov + * @library /test/jdk/java/io/Serializable/subclassGC/ + * @build SubclassOfOOS + * @run main/othervm/policy=security.policy -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer SubclassGC + */ diff --git a/test/jdk/java/io/FastSerializer/subclassGC/security.policy b/test/jdk/java/io/FastSerializer/subclassGC/security.policy new file mode 100644 index 000000000..a3ef804b3 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/subclassGC/security.policy @@ -0,0 +1,8 @@ + +grant { + permission java.lang.RuntimePermission "createClassLoader"; + permission java.lang.RuntimePermission "getClassLoader"; + permission java.util.PropertyPermission "test.classes", "read"; + permission java.io.FilePermission "<>", "read"; +}; + diff --git a/test/jdk/java/io/FastSerializer/superclassDataLoss/A.java b/test/jdk/java/io/FastSerializer/superclassDataLoss/A.java new file mode 100644 index 000000000..a1e976307 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/superclassDataLoss/A.java @@ -0,0 +1,13 @@ + + +/* + * @bug 4325590 + * @summary Verify that superclass data is not lost when incoming superclass + * descriptor is matched with local class that is not a superclass of + * the deserialized instance's class. + */ + +public class A implements java.io.Serializable { + protected final int i; + protected A(int i) { this.i = i; } +} diff --git a/test/jdk/java/io/FastSerializer/superclassDataLoss/B.java b/test/jdk/java/io/FastSerializer/superclassDataLoss/B.java new file mode 100644 index 000000000..eca1c0b8a --- /dev/null +++ b/test/jdk/java/io/FastSerializer/superclassDataLoss/B.java @@ -0,0 +1,19 @@ + + +/* + * @bug 4325590 + * @summary Verify that superclass data is not lost when incoming superclass + * descriptor is matched with local class that is not a superclass of + * the deserialized instance's class. + */ + +public class B extends A implements Runnable { + public B() { super(0xDEADBEEF); } + + // verify superclass data still present + public void run() { + if (i != 0xDEADBEEF) { + throw new Error("superclass data erased"); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/superclassDataLoss/TestDescription.java b/test/jdk/java/io/FastSerializer/superclassDataLoss/TestDescription.java new file mode 100644 index 000000000..b8831114c --- /dev/null +++ b/test/jdk/java/io/FastSerializer/superclassDataLoss/TestDescription.java @@ -0,0 +1,24 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/superclassDataLoss +*- @TestCaseName:superclassDataLoss +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* + * @test + * @bug 4325590 + * @library /test/lib/ /test/jdk/java/io/Serializable/superclassDataLoss/ + * @build jdk.test.lib.util.JarUtils A B + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer SuperclassDataLossTest + * @summary Verify that superclass data is not lost when incoming superclass + * descriptor is matched with local class that is not a superclass of + * the deserialized instance's class. + */ diff --git a/test/jdk/java/io/FastSerializer/survivePrematureClose/TestDescription.java b/test/jdk/java/io/FastSerializer/survivePrematureClose/TestDescription.java new file mode 100644 index 000000000..d09547a8d --- /dev/null +++ b/test/jdk/java/io/FastSerializer/survivePrematureClose/TestDescription.java @@ -0,0 +1,23 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/survivePrematureClose +*- @TestCaseName:survivePrematureClose +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4502808 + * @library /test/jdk/java/io/Serializable/survivePrematureClose/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer SurvivePrematureClose + * @summary Verify that if the custom serialization method (i.e., readExternal, + * writeExternal, readObject or writeObject) of an object closes the + * stream it is passed, (de)serialization of that object can still + * complete. + */ diff --git a/test/jdk/java/io/FastSerializer/typeSafeEnum/TestDescription.java b/test/jdk/java/io/FastSerializer/typeSafeEnum/TestDescription.java new file mode 100644 index 000000000..c0469a8f0 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/typeSafeEnum/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/typeSafeEnum +*- @TestCaseName:typeSafeEnum +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4140729 + * @library /test/jdk/java/io/Serializable/typeSafeEnum/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer TypeSafeEnum + * @summary Verify that writeReplace & readResolve are called by serialization. + * readResolve is used to maintain the invariant that the enums + * of TypeSafeEnum are singletons. + */ diff --git a/test/jdk/java/io/FastSerializer/typeStringBackRef/TypeStringBackRef.java b/test/jdk/java/io/FastSerializer/typeStringBackRef/TypeStringBackRef.java new file mode 100644 index 000000000..1efe3668a --- /dev/null +++ b/test/jdk/java/io/FastSerializer/typeStringBackRef/TypeStringBackRef.java @@ -0,0 +1,37 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/TypeStringBackRef +*- @TestCaseName:TypeStringBackRef +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4405949 + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer TypeStringBackRef + * @summary Verify that back references are used when writing multiple type + * strings that are equal() to one another. + */ + +import java.io.*; + +public class TypeStringBackRef implements Serializable { + + String a, b, c, d, e, f, g; + + public static void main(String[] args) throws Exception { + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + ObjectOutputStream oout = new ObjectOutputStream(bout); + oout.writeObject(ObjectStreamClass.lookup(TypeStringBackRef.class)); + oout.close(); + if (bout.size() != 25) { + throw new Error("Wrong data length: " + bout.size()); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/unSerializable/serialPersistentFieldsExt.java b/test/jdk/java/io/FastSerializer/unSerializable/serialPersistentFieldsExt.java new file mode 100644 index 000000000..08aeee569 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unSerializable/serialPersistentFieldsExt.java @@ -0,0 +1,94 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/serialPersistentFieldsExt +*- @TestCaseName:serialPersistentFieldsExt +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test static field cannot be deserialized +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true serialPersistentFieldsExt +*/ + + +import java.io.*; + +class Foo implements Externalizable { + transient int i ; + String s ; + public Foo(){} + Foo (int i, String s) { + this.i = i; + this.s = s; + } + private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField("i", int.class) }; + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s) ); + } +} + + +public class serialPersistentFieldsExt { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/unSerializable/serialPersistentFieldsSer.java b/test/jdk/java/io/FastSerializer/unSerializable/serialPersistentFieldsSer.java new file mode 100644 index 000000000..bc7e8860c --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unSerializable/serialPersistentFieldsSer.java @@ -0,0 +1,84 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/serialPersistentFieldsSer +*- @TestCaseName:serialPersistentFieldsSer +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test static field cannot be deserialized +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true serialPersistentFieldsSer +*/ + + +import java.io.*; + + +class Foo implements Serializable { + Foo (int i, String s) { + this.i = i; + this.s = s; + } + int i = 0; + String s ; + + private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField("i", int.class) }; + + public boolean equals(Foo obj) { + return (this.i == obj.i); + } +} + +public class serialPersistentFieldsSer { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + + if(!f1.equals(fout1) || !f2.equals(fout2) ||!f3.equals(fout3) ||!f4.equals(fout4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + + if(!f1.equals(fout5) || !f2.equals(fout6) ||!f3.equals(fout7) ||!f4.equals(fout8)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/unSerializable/staticExternal.java b/test/jdk/java/io/FastSerializer/unSerializable/staticExternal.java new file mode 100644 index 000000000..0f4761fc0 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unSerializable/staticExternal.java @@ -0,0 +1,94 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/staticExternal +*- @TestCaseName:staticExternal +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test static field cannot be deserialized +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true staticExternal +*/ + + +import java.io.*; + + +class Foo implements Externalizable { + static int i ; + static String s ; + public Foo(){} + Foo (int i, String s) { + this.i = i; + this.s = s; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s) ); + } +} + +public class staticExternal { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/unSerializable/staticSerializ.java b/test/jdk/java/io/FastSerializer/unSerializable/staticSerializ.java new file mode 100644 index 000000000..a68806e59 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unSerializable/staticSerializ.java @@ -0,0 +1,82 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/staticSerializ +*- @TestCaseName:staticSerializ +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test static field cannot be deserialized +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true staticSerializ +*/ + + +import java.io.*; + + +class Foo implements Serializable { + Foo (int i, String s) { + this.i = i; + this.s = s; + } + static int i = 0; + String s ; + + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s)); + } +} + +public class staticSerializ { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + + if(!fout1.equals(f1) || !fout2.equals(f2) ||!fout3.equals(f3) ||!fout4.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + + if(!fout5.equals(f1) || !fout6.equals(f2) ||!fout7.equals(f3) ||!fout8.equals(f4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/unSerializable/transientExternal.java b/test/jdk/java/io/FastSerializer/unSerializable/transientExternal.java new file mode 100644 index 000000000..651449b3b --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unSerializable/transientExternal.java @@ -0,0 +1,99 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/transientExternal +*- @TestCaseName:transientExternal +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test transient field cannot be deserialized +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true transientSerializ +*/ + + +import java.io.*; + + +class Foo implements Externalizable { + transient int i ; + String s ; + public Foo(){} + Foo (int i, String s) { + this.i = i; + this.s = s; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + s = (String)in.readObject(); + i = in.readInt(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(s); + out.writeInt(i); + } + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s) ); + } +} + +public class transientSerializ { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + Foo fc1 = new Foo(0,"Hello"); + Foo fc2 = new Foo(0,"World"); + Foo fc3 = new Foo(0,"Good"); + Foo fc4 = new Foo(0,"Bye"); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + //System.out.println(f1.i); + + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + + if(!fout1.equals(fc1) || !fout2.equals(fc2) ||!fout3.equals(fc3) ||!fout4.equals(fc4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + + + if(!fout5.equals(fc1) || !fout6.equals(fc2) ||!fout7.equals(fc3) ||!fout8.equals(fc4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/unSerializable/transientSerializ.java b/test/jdk/java/io/FastSerializer/unSerializable/transientSerializ.java new file mode 100644 index 000000000..b5f179e58 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unSerializable/transientSerializ.java @@ -0,0 +1,87 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/transientSerializ +*- @TestCaseName:transientSerializ +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* +* @test +* @summary test transient field cannot be deserialized +* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer -DfastSerializerEscapeMode=true -DprintFastSerializer=true transientSerializ +*/ + + +import java.io.*; + + +class Foo implements Serializable { + Foo (int i, String s) { + this.i = i; + this.s = s; + } + transient int i = 0; + String s ; + + public boolean equals(Foo obj) { + return (this.i == obj.i && this.s.equals(obj.s)); + } +} + +public class transientSerializ { + public static void main(String[] args) throws Exception{ + String configFile = System.getProperty("test.src") + "/../logging.properties"; + System.setProperty("java.util.logging.config.file",configFile); + Foo f1 = new Foo(1,"Hello"); + Foo f2 = new Foo(2,"World"); + Foo f3 = new Foo(3,"Good"); + Foo f4 = new Foo(4,"Bye"); + Foo fc1 = new Foo(0,"Hello"); + Foo fc2 = new Foo(0,"World"); + Foo fc3 = new Foo(0,"Good"); + Foo fc4 = new Foo(0,"Bye"); + ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("Foo.ser")); + oout.writeObject(f1); + oout.writeObject(f2); + oout.writeObject(f3); + oout.writeObject(f4); + oout.close(); + //System.out.println(f1.i); + + ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Foo.ser")); + try{ + Foo fout1 = (Foo)oin.readObject(); + Foo fout2 = (Foo)oin.readObject(); + Foo fout3 = (Foo)oin.readObject(); + Foo fout4 = (Foo)oin.readObject(); + oin.close(); + + if(!fout1.equals(fc1) || !fout2.equals(fc2) ||!fout3.equals(fc3) ||!fout4.equals(fc4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + ObjectInputStream oin2 = new ObjectInputStream(new FileInputStream("Foo.ser")); + try { + Foo fout5 = (Foo)oin2.readObject(); + Foo fout6 = (Foo)oin2.readObject(); + Foo fout7 = (Foo)oin2.readObject(); + Foo fout8 = (Foo)oin2.readObject(); + + + if(!fout5.equals(fc1) || !fout6.equals(fc2) ||!fout7.equals(fc3) ||!fout8.equals(fc4)){ + throw new Exception("deserialized obj different"); + } + }catch (ClassCastException ex){ + return; + } + } +} diff --git a/test/jdk/java/io/FastSerializer/underlyingOutputStreamException/TestDescription.java b/test/jdk/java/io/FastSerializer/underlyingOutputStreamException/TestDescription.java new file mode 100644 index 000000000..07f26c71a --- /dev/null +++ b/test/jdk/java/io/FastSerializer/underlyingOutputStreamException/TestDescription.java @@ -0,0 +1,21 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/underlyingOutputStreamException +*- @TestCaseName:underlyingOutputStreamException +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @library /test/jdk/java/io/Serializable/underlyingOutputStreamException/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer UnderlyingOutputStreamException + * @summary Verify that if ObjectOutputStream's underlying OutputStream throws + * an IOException, the original IOException (not a + * StreamCorruptedException) will be thrown to the writing thread. + */ diff --git a/test/jdk/java/io/FastSerializer/unnamedPackageSwitch/TestDescription.java b/test/jdk/java/io/FastSerializer/unnamedPackageSwitch/TestDescription.java new file mode 100644 index 000000000..cd67b02b5 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unnamedPackageSwitch/TestDescription.java @@ -0,0 +1,25 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/unnamedPackageSwitch +*- @TestCaseName:unnamedPackageSwitch +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* + * @test + * @bug 4348213 + * @library /test/jdk/java/io/Serializable/unnamedPackageSwitch/ + * @build pkg.A + * @build UnnamedPackageSwitchTest + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer UnnamedPackageSwitchTest + * @summary Verify that deserialization allows an incoming class descriptor + * representing a class in the unnamed package to be resolved to a + * local class with the same name in a named package, and vice-versa. + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/unnamedPackageSwitch/pkg/A.java b/test/jdk/java/io/FastSerializer/unnamedPackageSwitch/pkg/A.java new file mode 100644 index 000000000..d86764b1a --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unnamedPackageSwitch/pkg/A.java @@ -0,0 +1,14 @@ + +/* + * @bug 4348213 + * @summary Verify that deserialization allows an incoming class descriptor + * representing a class in the default package to be resolved to a + * local class with the same name in a non-default package, and + * vice-versa. + */ + +package pkg; + +public class A implements java.io.Serializable { + private static final long serialVersionUID = 0L; +} diff --git a/test/jdk/java/io/FastSerializer/unresolvableObjectStreamClass/TestDescription.java b/test/jdk/java/io/FastSerializer/unresolvableObjectStreamClass/TestDescription.java new file mode 100644 index 000000000..dea2171e5 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unresolvableObjectStreamClass/TestDescription.java @@ -0,0 +1,24 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/unresolvableObjectStreamClass +*- @TestCaseName:unresolvableObjectStreamClass +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 8039396 + * @library /test/jdk/java/io/Serializable/unresolvableObjectStreamClass/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer UnresolvableObjectStreamClass serialize + * @clean MySerializable + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer UnresolvableObjectStreamClass deserialize + * + * @summary NPE when writing a class descriptor object to a custom + * ObjectOutputStream + */ diff --git a/test/jdk/java/io/FastSerializer/unresolvedClassDesc/Foo.java b/test/jdk/java/io/FastSerializer/unresolvedClassDesc/Foo.java new file mode 100644 index 000000000..60b058e5b --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unresolvedClassDesc/Foo.java @@ -0,0 +1,11 @@ + + +/* + * @bug 4482471 + * @summary Verify that even if an incoming ObjectStreamClass is not resolvable + * to a local class, the ObjectStreamClass object itself is still + * deserializable (without incurring a ClassNotFoundException). + */ + +public class Foo implements java.io.Serializable { +} diff --git a/test/jdk/java/io/FastSerializer/unresolvedClassDesc/Read.java b/test/jdk/java/io/FastSerializer/unresolvedClassDesc/Read.java new file mode 100644 index 000000000..a86646152 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unresolvedClassDesc/Read.java @@ -0,0 +1,32 @@ + +/* + * @bug 4482471 + * @summary Verify that even if an incoming ObjectStreamClass is not resolvable + * to a local class, the ObjectStreamClass object itself is still + * deserializable (without incurring a ClassNotFoundException). + */ + +import java.io.*; + +public class Read { + public static void main(String[] args) throws Exception { + FileInputStream in = new FileInputStream("tmp.ser"); + try { + ObjectInputStream oin = new ObjectInputStream(in); + oin.readObject(); + oin.readObject(); + try { + oin.readObject(); + throw new Error("read of Foo instance succeeded"); + } catch (ClassNotFoundException ex) { + } + try { + oin.readObject(); + throw new Error("indirect read of Foo instance succeeded"); + } catch (ClassNotFoundException ex) { + } + } finally { + in.close(); + } + } +} diff --git a/test/jdk/java/io/FastSerializer/unresolvedClassDesc/TestDescription.java b/test/jdk/java/io/FastSerializer/unresolvedClassDesc/TestDescription.java new file mode 100644 index 000000000..4bff2d805 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unresolvedClassDesc/TestDescription.java @@ -0,0 +1,30 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/unresolvedClassDesc +*- @TestCaseName:unresolvedClassDesc +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4482471 + * + * @library /test/jdk/java/io/Serializable/unresolvedClassDesc/ + * @clean Write Read Foo + * @build Write Foo + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Write + * @clean Write Foo + * @build Read + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Read + * @clean Read + * + * @summary Verify that even if an incoming ObjectStreamClass is not resolvable + * to a local class, the ObjectStreamClass object itself is still + * deserializable (without incurring a ClassNotFoundException). + */ diff --git a/test/jdk/java/io/FastSerializer/unresolvedClassDesc/Write.java b/test/jdk/java/io/FastSerializer/unresolvedClassDesc/Write.java new file mode 100644 index 000000000..34e559870 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unresolvedClassDesc/Write.java @@ -0,0 +1,33 @@ + + +/* @test + * @bug 4482471 + * + * @clean Write Read Foo + * @build Write Foo + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Write + * @clean Write Foo + * @build Read + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Read + * @clean Read + * + * @summary Verify that even if an incoming ObjectStreamClass is not resolvable + * to a local class, the ObjectStreamClass object itself is still + * deserializable (without incurring a ClassNotFoundException). + */ + +import java.io.*; + +public class Write { + public static void main(String[] args) throws Exception { + ObjectOutputStream oout = + new ObjectOutputStream(new FileOutputStream("tmp.ser")); + ObjectStreamClass desc = ObjectStreamClass.lookup(Foo.class); + Foo foo = new Foo(); + oout.writeObject(desc); + oout.writeObject(new Object[]{ desc }); // test indirect references + oout.writeObject(foo); + oout.writeObject(new Object[]{ foo }); + oout.close(); + } +} diff --git a/test/jdk/java/io/FastSerializer/unshared/TestDescription.java b/test/jdk/java/io/FastSerializer/unshared/TestDescription.java new file mode 100644 index 000000000..31fd11ca4 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/unshared/TestDescription.java @@ -0,0 +1,27 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/unshared +*- @TestCaseName:unshared +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4311991 + * + * @library /test/jdk/java/io/Serializable/unshared/ + * @clean Write Read Foo Bar + * @build Write + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Write + * @clean Write Read Foo Bar + * @build Read + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Read + * + * @summary Test ObjectOutputStream.writeUnshared/readUnshared functionality. + */ diff --git a/test/jdk/java/io/FastSerializer/userRWObjError/TestDescription.java b/test/jdk/java/io/FastSerializer/userRWObjError/TestDescription.java new file mode 100644 index 000000000..f2e94df9b --- /dev/null +++ b/test/jdk/java/io/FastSerializer/userRWObjError/TestDescription.java @@ -0,0 +1,21 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/userRWObjError +*- @TestCaseName:userRWObjError +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4082734 + * @library /test/jdk/java/io/Serializable/userRWObjError/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer UserRWObjError + * @summary Ensure that Error exception is propogated from Serializable class' + * readObject & writeObject method. + */ diff --git a/test/jdk/java/io/FastSerializer/util/CleanActualClass.java b/test/jdk/java/io/FastSerializer/util/CleanActualClass.java new file mode 100644 index 000000000..c19e7b0ce --- /dev/null +++ b/test/jdk/java/io/FastSerializer/util/CleanActualClass.java @@ -0,0 +1,44 @@ +// !!! +// NOTE: this class is only used for FastSerializer test. +// !!! +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * Clean class file , using relative paths which are actual serialalbe directory. + */ +public class CleanActualClass { + public static final String TEST_ClASS = System.getProperty("test.classes", "").trim(); + + /** + * @param args files + * @throws IOException if an I/O error occurs + */ + public static void main(String[] args) throws IOException { + if (args.length == 0) { + throw new IllegalArgumentException("At least one file must be specified to clean"); + } + String base = TEST_ClASS.replace("TestDescription.d", ""); + String rep = "/java/io/FastSerializer/"; + int pos = base.lastIndexOf(rep); + if (pos != -1) { + StringBuilder builder = new StringBuilder(); + builder.append(base.substring(0, pos)); + builder.append("/test/jdk/java/io/Serializable/"); + builder.append(base.substring(pos + rep.length())); + base = builder.toString(); + } + + for (String arg:args) { + Path path = Paths.get(base, arg).toAbsolutePath().normalize(); + if (Files.deleteIfExists(path)) { + System.out.printf("delete " + path + " success\n"); + } else { + System.out.printf("file " + path + " doesn't exist\n"); + } + } + } +} + diff --git a/test/jdk/java/io/FastSerializer/validate/TestDescription.java b/test/jdk/java/io/FastSerializer/validate/TestDescription.java new file mode 100644 index 000000000..e5123514d --- /dev/null +++ b/test/jdk/java/io/FastSerializer/validate/TestDescription.java @@ -0,0 +1,22 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/validate +*- @TestCaseName:validate +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* + * @test + * @bug 4094892 + * @summary Verify that an object is not validated more than once during deserialization. + * @library /test/jdk/java/io/Serializable/validate/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Validate + * + */ \ No newline at end of file diff --git a/test/jdk/java/io/FastSerializer/verifyDynamicObjHandleTable/TestDescription.java b/test/jdk/java/io/FastSerializer/verifyDynamicObjHandleTable/TestDescription.java new file mode 100644 index 000000000..d88cbda07 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/verifyDynamicObjHandleTable/TestDescription.java @@ -0,0 +1,20 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/verifyDynamicObjHandleTable +*- @TestCaseName:verifyDynamicObjHandleTable +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4146453 + * @library /test/jdk/java/io/Serializable/verifyDynamicObjHandleTable/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer VerifyDynamicObjHandleTable + * @summary Test that regrow of object/handle table of ObjectOutputStream works. + */ diff --git a/test/jdk/java/io/FastSerializer/writeObjectMemory/TestDescription.java b/test/jdk/java/io/FastSerializer/writeObjectMemory/TestDescription.java new file mode 100644 index 000000000..20b59bb43 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/writeObjectMemory/TestDescription.java @@ -0,0 +1,21 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/writeObjectMemory +*- @TestCaseName:writeObjectMemory +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @library /test/jdk/java/io/Serializable/writeObjectMemory/ + * @clean A WriteObjectMemory + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer WriteObjectMemory + * @bug 4146453 5011410 + * @summary Test that regrow of object/handle table of ObjectOutputStream works. + */ diff --git a/test/jdk/java/io/FastSerializer/writeReplace/TestDescription.java b/test/jdk/java/io/FastSerializer/writeReplace/TestDescription.java new file mode 100644 index 000000000..6dd013c67 --- /dev/null +++ b/test/jdk/java/io/FastSerializer/writeReplace/TestDescription.java @@ -0,0 +1,19 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/writeReplace +*- @TestCaseName:writeReplace +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @library /test/jdk/java/io/Serializable/writeReplace/ + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer WriteReplace + * @summary Test proper functioning of class-defined writeReplace methods. + */ diff --git a/test/jdk/java/io/FastSerializer/wrongReturnTypes/TestDescription.java b/test/jdk/java/io/FastSerializer/wrongReturnTypes/TestDescription.java new file mode 100644 index 000000000..f5acfee1e --- /dev/null +++ b/test/jdk/java/io/FastSerializer/wrongReturnTypes/TestDescription.java @@ -0,0 +1,28 @@ +/* +*- @TestCaseID:jdk17/FastSerializer/wrongReturnTypes +*- @TestCaseName:wrongReturnTypes +*- @TestCaseType:Function test +*- @RequirementID:AR.SR.IREQ02478866.001.001 +*- @RequirementName:FastSeralizer 功能实现 +*- @Condition:UseFastSerializer +*- @Brief: +* -#step1 将对象写入数据流 +* -#step2 从数据流中读取对象 +*- @Expect: 读取对象与写入对象相同 +*- @Priority:Level 1 +*/ + +/* @test + * @bug 4337857 + * + * @library /test/jdk/java/io/Serializable/wrongReturnTypes/ + * @clean Write Read A B + * @build Write + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Write + * @clean Write Read A B + * @build Read + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseFastSerializer Read + * + * @summary Verify that custom serialization methods declared with incorrect + * return types are not invoked. + */ -- 2.37.0