1 /* |
1 /* |
2 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
54 import java.io.InvalidClassException; |
54 import java.io.InvalidClassException; |
55 import java.io.Serializable; |
55 import java.io.Serializable; |
56 |
56 |
57 import java.util.Arrays; |
57 import java.util.Arrays; |
58 import java.util.Comparator; |
58 import java.util.Comparator; |
59 import java.util.Hashtable; |
|
60 |
59 |
61 import com.sun.corba.se.impl.util.RepositoryId; |
60 import com.sun.corba.se.impl.util.RepositoryId; |
62 |
61 |
63 import org.omg.CORBA.ValueMember; |
62 import org.omg.CORBA.ValueMember; |
64 |
63 |
80 |
79 |
81 public static final long kDefaultUID = -1; |
80 public static final long kDefaultUID = -1; |
82 |
81 |
83 private static Object noArgsList[] = {}; |
82 private static Object noArgsList[] = {}; |
84 private static Class noTypesList[] = {}; |
83 private static Class noTypesList[] = {}; |
85 |
|
86 private static Hashtable translatedFields; |
|
87 |
84 |
88 /** true if represents enum type */ |
85 /** true if represents enum type */ |
89 private boolean isEnum; |
86 private boolean isEnum; |
90 |
87 |
91 private static final Bridge bridge = |
88 private static final Bridge bridge = |
382 * after the lock on the global class descriptor table has been |
379 * after the lock on the global class descriptor table has been |
383 * released. |
380 * released. |
384 */ |
381 */ |
385 } |
382 } |
386 |
383 |
|
384 private static final class PersistentFieldsValue |
|
385 extends ClassValue<ObjectStreamField[]> { |
|
386 PersistentFieldsValue() { } |
|
387 |
|
388 protected ObjectStreamField[] computeValue(Class<?> type) { |
|
389 try { |
|
390 Field pf = type.getDeclaredField("serialPersistentFields"); |
|
391 int mods = pf.getModifiers(); |
|
392 if (Modifier.isPrivate(mods) && Modifier.isStatic(mods) && |
|
393 Modifier.isFinal(mods)) { |
|
394 pf.setAccessible(true); |
|
395 java.io.ObjectStreamField[] fields = |
|
396 (java.io.ObjectStreamField[])pf.get(type); |
|
397 return translateFields(fields); |
|
398 } |
|
399 } catch (NoSuchFieldException | IllegalAccessException | |
|
400 IllegalArgumentException | ClassCastException e) { |
|
401 } |
|
402 return null; |
|
403 } |
|
404 |
|
405 private static ObjectStreamField[] translateFields( |
|
406 java.io.ObjectStreamField[] fields) { |
|
407 ObjectStreamField[] translation = |
|
408 new ObjectStreamField[fields.length]; |
|
409 for (int i = 0; i < fields.length; i++) { |
|
410 translation[i] = new ObjectStreamField(fields[i].getName(), |
|
411 fields[i].getType()); |
|
412 } |
|
413 return translation; |
|
414 } |
|
415 } |
|
416 |
|
417 private static final PersistentFieldsValue persistentFieldsValue = |
|
418 new PersistentFieldsValue(); |
|
419 |
387 /* |
420 /* |
388 * Initialize class descriptor. This method is only invoked on class |
421 * Initialize class descriptor. This method is only invoked on class |
389 * descriptors created via calls to lookupInternal(). This method is kept |
422 * descriptors created via calls to lookupInternal(). This method is kept |
390 * separate from the ObjectStreamClass constructor so that lookupInternal |
423 * separate from the ObjectStreamClass constructor so that lookupInternal |
391 * does not have to hold onto a global class descriptor table lock while the |
424 * does not have to hold onto a global class descriptor table lock while the |
414 public Object run() { |
447 public Object run() { |
415 /* Fill in the list of persistent fields. |
448 /* Fill in the list of persistent fields. |
416 * If it is declared, use the declared serialPersistentFields. |
449 * If it is declared, use the declared serialPersistentFields. |
417 * Otherwise, extract the fields from the class itself. |
450 * Otherwise, extract the fields from the class itself. |
418 */ |
451 */ |
419 try { |
452 fields = persistentFieldsValue.get(cl); |
420 Field pf = cl.getDeclaredField("serialPersistentFields"); |
|
421 // serial bug 7; the serialPersistentFields were not |
|
422 // being read and stored as Accessible bit was not set |
|
423 pf.setAccessible(true); |
|
424 // serial bug 7; need to find if the field is of type |
|
425 // java.io.ObjectStreamField |
|
426 java.io.ObjectStreamField[] f = |
|
427 (java.io.ObjectStreamField[])pf.get(cl); |
|
428 int mods = pf.getModifiers(); |
|
429 if ((Modifier.isPrivate(mods)) && |
|
430 (Modifier.isStatic(mods)) && |
|
431 (Modifier.isFinal(mods))) |
|
432 { |
|
433 fields = (ObjectStreamField[])translateFields((Object[])pf.get(cl)); |
|
434 } |
|
435 } catch (NoSuchFieldException e) { |
|
436 fields = null; |
|
437 } catch (IllegalAccessException e) { |
|
438 fields = null; |
|
439 } catch (IllegalArgumentException e) { |
|
440 fields = null; |
|
441 } catch (ClassCastException e) { |
|
442 /* Thrown if a field serialPersistentField exists |
|
443 * but it is not of type ObjectStreamField. |
|
444 */ |
|
445 fields = null; |
|
446 } |
|
447 |
|
448 |
453 |
449 if (fields == null) { |
454 if (fields == null) { |
450 /* Get all of the declared fields for this |
455 /* Get all of the declared fields for this |
451 * Class. setAccessible on all fields so they |
456 * Class. setAccessible on all fields so they |
452 * can be accessed later. Create a temporary |
457 * can be accessed later. Create a temporary |
639 name = n; |
644 name = n; |
640 suid = s; |
645 suid = s; |
641 superclass = null; |
646 superclass = null; |
642 } |
647 } |
643 |
648 |
644 private static Object[] translateFields(Object objs[]) |
|
645 throws NoSuchFieldException { |
|
646 try{ |
|
647 java.io.ObjectStreamField fields[] = (java.io.ObjectStreamField[])objs; |
|
648 Object translation[] = null; |
|
649 |
|
650 if (translatedFields == null) |
|
651 translatedFields = new Hashtable(); |
|
652 |
|
653 translation = (Object[])translatedFields.get(fields); |
|
654 |
|
655 if (translation != null) |
|
656 return translation; |
|
657 else { |
|
658 Class osfClass = Class.forName("com.sun.corba.se.impl.io.ObjectStreamField"); |
|
659 translation = (Object[])java.lang.reflect.Array.newInstance(osfClass, objs.length); |
|
660 Object arg[] = new Object[2]; |
|
661 Class types[] = {String.class, Class.class}; |
|
662 Constructor constructor = osfClass.getDeclaredConstructor(types); |
|
663 for (int i = fields.length -1; i >= 0; i--){ |
|
664 arg[0] = fields[i].getName(); |
|
665 arg[1] = fields[i].getType(); |
|
666 |
|
667 translation[i] = constructor.newInstance(arg); |
|
668 } |
|
669 translatedFields.put(fields, translation); |
|
670 |
|
671 } |
|
672 |
|
673 return (Object[])translation; |
|
674 } |
|
675 catch(Throwable t){ |
|
676 NoSuchFieldException nsfe = new NoSuchFieldException(); |
|
677 nsfe.initCause( t ) ; |
|
678 throw nsfe ; |
|
679 } |
|
680 } |
|
681 |
649 |
682 /* |
650 /* |
683 * Set the class this version descriptor matches. |
651 * Set the class this version descriptor matches. |
684 * The base class name and serializable hash must match. |
652 * The base class name and serializable hash must match. |
685 * Fill in the reflected Fields that will be used |
653 * Fill in the reflected Fields that will be used |