/*
* 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 .
*/
/*
* @ test
* @ bug 6739302
* @ summary Check that deserialization preserves EnumSet integrity
* @ author Josh Bloch
*/
import java.util.*;
import java.io.*;
public class BogusEnumSet {
public static void main(String[] args) throws Throwable {
// This test tries to deserialize a bogus stream produced with
// hypothetical EnumSet without a writeReplace() method - i.e.
// not using serialization proxy pattern. It tests that such
// stream is not accepted as valid stream - the EnumSet class
// declares a readObject() method which throws exception.
byte [] serializedForm = {
(byte )0 xac, (byte )0 xed, 0 x0, 0 x5, 0 x73, 0 x72, 0 x0, 0 x18,
0 x6a, 0 x61, 0 x76, 0 x61, 0 x2e, 0 x75, 0 x74, 0 x69,
0 x6c, 0 x2e, 0 x52, 0 x65, 0 x67, 0 x75, 0 x6c, 0 x61, 0 x72, 0 x45,
0 x6e, 0 x75, 0 x6d, 0 x53, 0 x65, 0 x74, 0 x2f, 0 x58, 0 x6f, (byte )0 xc7,
0 x7e, (byte )0 xb0, (byte )0 xd0, 0 x7e, 0 x2, 0 x0, 0 x1, 0 x4a, 0 x0, 0 x8,
0 x65, 0 x6c, 0 x65, 0 x6d, 0 x65, 0 x6e, 0 x74, 0 x73, 0 x78, 0 x72, 0 x0,
0 x11, 0 x6a, 0 x61, 0 x76, 0 x61, 0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 0 x19, 0 x5b, 0 x4c, 0 x6a, 0 x61, 0 x76, 0 x61,
0 x2e, 0 x6c, 0 x61, 0 x6e, 0 x67, 0 x2e, 0 x54, 0 x68, 0 x72, 0 x65, 0 x61,
0 x64, 0 x24, 0 x53, 0 x74, 0 x61, 0 x74, 0 x65, 0 x3b, 0 x68, (byte )0 xa3,
(byte )0 xb5, (byte )0 xd5, 0 x11, 0 x7d, 0 x1b, (byte )0 xb3, 0 x2, 0 x0,
0 x0, 0 x78, 0 x70, 0 x0, 0 x0, 0 x0, 0 x6, 0 x7e, 0 x71, 0 x0, 0 x7e, 0 x0,
0 x5, 0 x74, 0 x0, 0 x3, 0 x4e, 0 x45, 0 x57, 0 x7e, 0 x71, 0 x0, 0 x7e, 0 x0,
0 x5, 0 x74, 0 x0, 0 x8, 0 x52, 0 x55, 0 x4e, 0 x4e, 0 x41, 0 x42, 0 x4c, 0 x45,
0 x7e, 0 x71, 0 x0, 0 x7e, 0 x0, 0 x5, 0 x74, 0 x0, 0 x7, 0 x42, 0 x4c, 0 x4f,
0 x43, 0 x4b, 0 x45, 0 x44, 0 x7e, 0 x71, 0 x0, 0 x7e, 0 x0, 0 x5, 0 x74, 0 x0,
0 x7, 0 x57, 0 x41, 0 x49, 0 x54, 0 x49, 0 x4e, 0 x47, 0 x7e, 0 x71, 0 x0,
0 x7e, 0 x0, 0 x5, 0 x74, 0 x0, 0 xd, 0 x54, 0 x49, 0 x4d, 0 x45, 0 x44,
0 x5f, 0 x57, 0 x41, 0 x49, 0 x54, 0 x49, 0 x4e, 0 x47, 0 x7e, 0 x71, 0 x0,
0 x7e, 0 x0, 0 x5, 0 x74, 0 x0, 0 xa, 0 x54, 0 x45, 0 x52, 0 x4d, 0 x49,
0 x4e, 0 x41, 0 x54, 0 x45, 0 x44, (byte )0 xff, (byte )0 xff, (byte )0 xff,
(byte )0 xff, (byte )0 xff, (byte )0 xff, (byte )0 xff, (byte )0 xff
};
try {
// Should fail, but instead creates corrupt EnumSet
@SuppressWarnings("unchecked" )
EnumSet<Thread .State> es = (EnumSet<Thread .State>)
deserialize(serializedForm);
// Demonstrates corruption
System.out.println("Enum size: " + Thread .State.values().length); // 6
System.out.println("Set size: " + es.size()); // 64
System.out.println("Set: " + es); // Throws IndexOutOfBoundsException
throw new AssertionError("Expected exception InvalidObjectException not thrown" );
} catch (java.io.InvalidObjectException expected) { /* OK */ }
}
private static Object deserialize(byte [] sf) throws Throwable {
return new ObjectInputStream(
new ByteArrayInputStream(sf))
.readObject();
}
}
Messung V0.5 in Prozent C=95 H=90 G=92