aboutsummaryrefslogtreecommitdiff
path: root/agent/src/share/classes/sun/jvm/hotspot/utilities/ObjectReader.java
blob: 55cb299562107531bbe1639b57bed94d6a6c66f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
/*
 * Copyright (c) 2002, 2007, 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 sun.jvm.hotspot.utilities;

import java.lang.reflect.Modifier;
import java.util.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.oops.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.utilities.*;

/**
 * ObjectReader can "deserialize" objects from debuggee.
 *
 * Class Loading:
 *
 * ObjectReader loads classes using the given class loader. If no
 * class loader is supplied, it uses a ProcImageClassLoader, which
 * loads classes from debuggee core or process.

 * Object creation:
 *
 * This class uses no-arg constructor to construct objects. But if
 * there is no no-arg constructor in a given class, then it tries to
 * use other constructors with 'default' values - null for object
 * types, 0, 0.0, false etc. for primitives.  If this process fails to
 * construct an instance (because of null checking by constructor or 0
 * being invalid for an int arg etc.), then null is returned. While
 * constructing complete object graph 'null' is inserted silently on
 * failure and the deserialization continues to construct best-effort
 * object graph.
 *
 * Debug messages:
 *
 * The flag sun.jvm.hotspot.utilities.ObjectReader.DEBUG may be set to
 * non-null to get debug error messages and stack traces.
 *
 * JDK version:
 *
 * JDK classes are loaded by bootstrap class loader and not by the
 * supplied class loader or ProcImageClassLoader. This may create
 * problems if a JDK class evolves. i.e., if SA runs a JDK version
 * different from that of the debuggee, there is a possibility of
 * schema change. It is recommended that the matching JDK version be
 * used to run SA for proper object deserialization.
 *
 */

public class ObjectReader {

   private static final boolean DEBUG;
   static {
      DEBUG = System.getProperty("sun.jvm.hotspot.utilities.ObjectReader.DEBUG") != null;
   }

   public ObjectReader(ClassLoader cl) {
      this.cl = cl;
      this.oopToObjMap = new HashMap();
      this.fieldMap = new HashMap();
   }

   public ObjectReader() {
      this(new ProcImageClassLoader());
   }

   public Object readObject(Oop oop) throws ClassNotFoundException {
      if (oop instanceof Instance) {
         return readInstance((Instance) oop);
      } else if (oop instanceof TypeArray){
         return readPrimitiveArray((TypeArray)oop);
      } else if (oop instanceof ObjArray){
         return readObjectArray((ObjArray)oop);
      } else {
         return null;
      }
   }

   protected final Object getDefaultPrimitiveValue(Class clz) {
      if (clz == Boolean.TYPE) {
         return Boolean.FALSE;
      } else if (clz == Character.TYPE) {
         return new Character(' ');
      } else if (clz == Byte.TYPE) {
         return new Byte((byte) 0);
      } else if (clz == Short.TYPE) {
         return new Short((short) 0);
      } else if (clz == Integer.TYPE) {
         return new Integer(0);
      } else if (clz == Long.TYPE) {
         return new Long(0L);
      } else if (clz == Float.TYPE) {
         return new Float(0.0f);
      } else if (clz == Double.TYPE) {
         return new Double(0.0);
      } else {
         throw new RuntimeException("should not reach here!");
      }
   }

   protected Symbol javaLangString;
   protected Symbol javaLangString() {
      if (javaLangString == null) {
         javaLangString = VM.getVM().getSymbolTable().probe("java/lang/String");
      }
      return javaLangString;
   }

   public Object readInstance(Instance oop) throws ClassNotFoundException {
      Object result = getFromObjTable(oop);
      if (result == null) {
         InstanceKlass kls = (InstanceKlass) oop.getKlass();
         // Handle java.lang.String instances differently. As part of JSR-133, fields of immutable
         // classes have been made final. The algorithm below will not be able to read Strings from
         // debuggee (can't use reflection to set final fields). But, need to read Strings is very
         // important. FIXME: need a framework to handle many other special cases.
         if (kls.getName().equals(javaLangString())) {
            return OopUtilities.stringOopToString(oop);
         }

         Class clz = readClass(kls);
         try {
            result = clz.newInstance();
         } catch (Exception ex) {
            // no-arg constructor failed to create object. Let us try
            // to call constructors one-by-one with default arguments
            // (null for objects, 0/0.0 etc. for primitives) till we
            // succeed or fail on all constructors.

            java.lang.reflect.Constructor[] ctrs = clz.getDeclaredConstructors();
            for (int n = 0; n < ctrs.length; n++) {
               java.lang.reflect.Constructor c = ctrs[n];
               Class[] paramTypes = c.getParameterTypes();
               Object[] params = new Object[paramTypes.length];
               for (int i = 0; i < params.length; i++) {
                  if (paramTypes[i].isPrimitive()) {
                     params[i] = getDefaultPrimitiveValue(paramTypes[i]);
                  }
               }
               try {
                  c.setAccessible(true);
                  result = c.newInstance(params);
                  break;
               } catch (Exception exp) {
                  if (DEBUG) {
                     System.err.println("Can't create object using " + c);
                     exp.printStackTrace();
                  }
               }
            }
         }

         if (result != null) {
            putIntoObjTable(oop, result);
            oop.iterate(new FieldSetter(result), false);
         }
      }
      return result;
   }

   public Object readPrimitiveArray(final TypeArray array) {

      Object result = getFromObjTable(array);
      if (result == null) {
         int length = (int) array.getLength();
         TypeArrayKlass klass = (TypeArrayKlass) array.getKlass();
         int type = (int) klass.getElementType();
         switch (type) {
            case TypeArrayKlass.T_BOOLEAN: {
               final boolean[] arrayObj = new boolean[length];
               array.iterate(new DefaultOopVisitor() {
                                public void doBoolean(BooleanField field, boolean isVMField) {
                                   IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
                                   arrayObj[ifd.getIndex()] = field.getValue(array);
                                }
                            }, false);
               result = arrayObj;
               }
               break;

            case TypeArrayKlass.T_CHAR: {
               final char[] arrayObj = new char[length];
               array.iterate(new DefaultOopVisitor() {
                                public void doChar(CharField field, boolean isVMField) {
                                   IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
                                   arrayObj[ifd.getIndex()] = field.getValue(array);
                                }
                            }, false);
               result = arrayObj;
               }
               break;

            case TypeArrayKlass.T_FLOAT: {
               final float[] arrayObj = new float[length];
               array.iterate(new DefaultOopVisitor() {
                                public void doFloat(FloatField field, boolean isVMField) {
                                   IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
                                   arrayObj[ifd.getIndex()] = field.getValue(array);
                                }
                            }, false);
               result = arrayObj;
               }
               break;

            case TypeArrayKlass.T_DOUBLE: {
               final double[] arrayObj = new double[length];
               array.iterate(new DefaultOopVisitor() {
                                public void doDouble(DoubleField field, boolean isVMField) {
                                   IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
                                   arrayObj[ifd.getIndex()] = field.getValue(array);
                                }
                            }, false);
               result = arrayObj;
               }
               break;

            case TypeArrayKlass.T_BYTE: {
               final byte[] arrayObj = new byte[length];
               array.iterate(new DefaultOopVisitor() {
                                public void doByte(ByteField field, boolean isVMField) {
                                   IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
                                   arrayObj[ifd.getIndex()] = field.getValue(array);
                                }
                            }, false);
               result = arrayObj;
               }
               break;

            case TypeArrayKlass.T_SHORT: {
               final short[] arrayObj = new short[length];
               array.iterate(new DefaultOopVisitor() {
                                public void doShort(ShortField field, boolean isVMField) {
                                   IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
                                   arrayObj[ifd.getIndex()] = field.getValue(array);
                                }
                            }, false);
               result = arrayObj;
               }
               break;

            case TypeArrayKlass.T_INT: {
               final int[] arrayObj = new int[length];
               array.iterate(new DefaultOopVisitor() {
                                public void doInt(IntField field, boolean isVMField) {
                                   IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
                                   arrayObj[ifd.getIndex()] = field.getValue(array);
                                }
                            }, false);
               result = arrayObj;
               }
               break;

            case TypeArrayKlass.T_LONG: {
               final long[] arrayObj = new long[length];
               array.iterate(new DefaultOopVisitor() {
                                public void doLong(LongField field, boolean isVMField) {
                                   IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
                                   arrayObj[ifd.getIndex()] = field.getValue(array);
                                }
                            }, false);
               result = arrayObj;
               }
               break;

            default:
               throw new RuntimeException("should not reach here!");
         }

         putIntoObjTable(array, result);
      }
      return result;
   }

   protected final boolean isRobust(OopHandle handle) {
      return RobustOopDeterminator.oopLooksValid(handle);
   }

   public Object readObjectArray(final ObjArray array) throws ClassNotFoundException {
       Object result = getFromObjTable(array);
       if (result == null) {
          int length = (int) array.getLength();
          ObjArrayKlass klass = (ObjArrayKlass) array.getKlass();
          Klass bottomKls = klass.getBottomKlass();
          Class bottomCls = null;
          final int dimension = (int) klass.getDimension();
          int[] dimArray = null;
          if (bottomKls instanceof InstanceKlass) {
             bottomCls = readClass((InstanceKlass) bottomKls);
             dimArray = new int[dimension];
          } else { // instanceof TypeArrayKlass
             TypeArrayKlass botKls = (TypeArrayKlass) bottomKls;
             dimArray = new int[dimension -1];
          }
          // initialize the length
          dimArray[0] = length;
          final Object[] arrayObj = (Object[]) java.lang.reflect.Array.newInstance(bottomCls, dimArray);
          putIntoObjTable(array, arrayObj);
          result = arrayObj;
          array.iterate(new DefaultOopVisitor() {
                               public void doOop(OopField field, boolean isVMField) {
                                  OopHandle handle = field.getValueAsOopHandle(getObj());
                                  if (! isRobust(handle)) {
                                     return;
                                  }

                                  IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
                                  try {
                                     arrayObj[ifd.getIndex()] = readObject(field.getValue(getObj()));
                                  } catch (Exception e) {
                                     if (DEBUG) {
                                        System.err.println("Array element set failed for " + ifd);
                                        e.printStackTrace();
                                     }
                                  }
                               }
                        }, false);
       }
       return result;
   }

   protected class FieldSetter extends DefaultOopVisitor {
      protected Object obj;

      public FieldSetter(Object obj) {
         this.obj = obj;
      }

      private void printFieldSetError(java.lang.reflect.Field f, Exception ex) {
         if (DEBUG) {
            if (f != null) System.err.println("Field set failed for " + f);
            ex.printStackTrace();
         }
      }

      // Callback methods for each field type in an object
      public void doOop(OopField field, boolean isVMField) {
         OopHandle handle = field.getValueAsOopHandle(getObj());
         if (! isRobust(handle) ) {
            return;
         }

         java.lang.reflect.Field f = null;
         try {
            f = readField(field);
            if (Modifier.isFinal(f.getModifiers())) return;
            f.setAccessible(true);
            f.set(obj, readObject(field.getValue(getObj())));
         } catch (Exception ex) {
            printFieldSetError(f, ex);
         }
      }

      public void doByte(ByteField field, boolean isVMField) {
         java.lang.reflect.Field f = null;
         try {
            f = readField(field);
            if (Modifier.isFinal(f.getModifiers())) return;
            f.setAccessible(true);
            f.setByte(obj, field.getValue(getObj()));
         } catch (Exception ex) {
            printFieldSetError(f, ex);
         }
      }

      public void doChar(CharField field, boolean isVMField) {
         java.lang.reflect.Field f = null;
         try {
            f = readField(field);
            if (Modifier.isFinal(f.getModifiers())) return;
            f.setAccessible(true);
            f.setChar(obj, field.getValue(getObj()));
         } catch (Exception ex) {
            printFieldSetError(f, ex);
         }
      }

      public void doBoolean(BooleanField field, boolean isVMField) {
         java.lang.reflect.Field f = null;
         try {
            f = readField(field);
            if (Modifier.isFinal(f.getModifiers())) return;
            f.setAccessible(true);
            f.setBoolean(obj, field.getValue(getObj()));
         } catch (Exception ex) {
            printFieldSetError(f, ex);
         }
      }

      public void doShort(ShortField field, boolean isVMField) {
         java.lang.reflect.Field f = null;
         try {
            f = readField(field);
            if (Modifier.isFinal(f.getModifiers())) return;
            f.setAccessible(true);
            f.setShort(obj, field.getValue(getObj()));
         } catch (Exception ex) {
            printFieldSetError(f, ex);
         }
      }

      public void doInt(IntField field, boolean isVMField) {
         java.lang.reflect.Field f = null;
         try {
            f = readField(field);
            if (Modifier.isFinal(f.getModifiers())) return;
            f.setAccessible(true);
            f.setInt(obj, field.getValue(getObj()));
         } catch (Exception ex) {
            printFieldSetError(f, ex);
         }
      }

      public void doLong(LongField field, boolean isVMField) {
         java.lang.reflect.Field f = null;
         try {
            f = readField(field);
            if (Modifier.isFinal(f.getModifiers())) return;
            f.setAccessible(true);
            f.setLong(obj, field.getValue(getObj()));
         } catch (Exception ex) {
            printFieldSetError(f, ex);
         }
      }

      public void doFloat(FloatField field, boolean isVMField) {
         java.lang.reflect.Field f = null;
         try {
            f = readField(field);
            if (Modifier.isFinal(f.getModifiers())) return;
            f.setAccessible(true);
            f.setFloat(obj, field.getValue(getObj()));
         } catch (Exception ex) {
            printFieldSetError(f, ex);
         }
      }

      public void doDouble(DoubleField field, boolean isVMField) {
         java.lang.reflect.Field f = null;
         try {
            f = readField(field);
            if (Modifier.isFinal(f.getModifiers())) return;
            f.setAccessible(true);
            f.setDouble(obj, field.getValue(getObj()));
         } catch (Exception ex) {
            printFieldSetError(f, ex);
         }
      }

      public void doCInt(CIntField field, boolean isVMField) {
         throw new RuntimeException("should not reach here!");
      }
   }

   public Class readClass(InstanceKlass kls) throws ClassNotFoundException {
      Class cls = (Class) getFromObjTable(kls);
      if (cls == null) {
         cls = Class.forName(kls.getName().asString().replace('/', '.'), true, cl);
         putIntoObjTable(kls, cls);
      }
      return cls;
   }

   public Object readMethodOrConstructor(sun.jvm.hotspot.oops.Method m)
                     throws NoSuchMethodException, ClassNotFoundException {
      String name = m.getName().asString();
      if (name.equals("<init>")) {
         return readConstructor(m);
      } else {
         return readMethod(m);
      }
   }

   public java.lang.reflect.Method readMethod(sun.jvm.hotspot.oops.Method m)
            throws NoSuchMethodException, ClassNotFoundException {
      java.lang.reflect.Method result = (java.lang.reflect.Method) getFromObjTable(m);
      if (result == null) {
         Class clz = readClass((InstanceKlass)m.getMethodHolder());
         String name = m.getName().asString();
         Class[] paramTypes = getParamTypes(m.getSignature());
         result = clz.getMethod(name, paramTypes);
         putIntoObjTable(m, result);
      }
      return result;
   }

   public java.lang.reflect.Constructor readConstructor(sun.jvm.hotspot.oops.Method m)
            throws NoSuchMethodException, ClassNotFoundException {
      java.lang.reflect.Constructor result = (java.lang.reflect.Constructor) getFromObjTable(m);
      if (result == null) {
         Class clz = readClass((InstanceKlass)m.getMethodHolder());
         String name = m.getName().asString();
         Class[] paramTypes = getParamTypes(m.getSignature());
         result = clz.getDeclaredConstructor(paramTypes);
         putIntoObjTable(m, result);
      }
      return result;
   }

   public java.lang.reflect.Field readField(sun.jvm.hotspot.oops.Field f)
            throws NoSuchFieldException, ClassNotFoundException {
      java.lang.reflect.Field result = (java.lang.reflect.Field) fieldMap.get(f);
      if (result == null) {
         FieldIdentifier fieldId = f.getID();
         Class clz = readClass((InstanceKlass) f.getFieldHolder());
         String name = fieldId.getName();
         try {
            result = clz.getField(name);
         } catch (NoSuchFieldException nsfe) {
            result = clz.getDeclaredField(name);
         }
         fieldMap.put(f, result);
      }
      return result;
   }

   protected final ClassLoader cl;
   protected Map   oopToObjMap; // Map<Oop, Object>
   protected Map   fieldMap;    // Map<sun.jvm.hotspot.oops.Field, java.lang.reflect.Field>

   protected void putIntoObjTable(Oop oop, Object obj) {
      oopToObjMap.put(oop, obj);
   }

   protected Object getFromObjTable(Oop oop) {
      return oopToObjMap.get(oop);
   }

   protected class SignatureParser extends SignatureIterator {
      protected Vector tmp = new Vector(); // Vector<Class>

      public SignatureParser(Symbol s) {
         super(s);
      }

      public void doBool  () { tmp.add(Boolean.TYPE);    }
      public void doChar  () { tmp.add(Character.TYPE);  }
      public void doFloat () { tmp.add(Float.TYPE);      }
      public void doDouble() { tmp.add(Double.TYPE);     }
      public void doByte  () { tmp.add(Byte.TYPE);       }
      public void doShort () { tmp.add(Short.TYPE);      }
      public void doInt   () { tmp.add(Integer.TYPE);    }
      public void doLong  () { tmp.add(Long.TYPE);       }
      public void doVoid  () {
         if(isReturnType()) {
            tmp.add(Void.TYPE);
         } else {
            throw new RuntimeException("should not reach here");
         }
      }

      public void doObject(int begin, int end) {
         tmp.add(getClass(begin, end));
      }

      public void doArray (int begin, int end) {
        int inner = arrayInnerBegin(begin);
        Class elemCls = null;
        switch (_signature.getByteAt(inner)) {
        case 'B': elemCls = Boolean.TYPE; break;
        case 'C': elemCls = Character.TYPE; break;
        case 'D': elemCls = Double.TYPE; break;
        case 'F': elemCls = Float.TYPE; break;
        case 'I': elemCls = Integer.TYPE; break;
        case 'J': elemCls = Long.TYPE; break;
        case 'S': elemCls = Short.TYPE; break;
        case 'Z': elemCls = Boolean.TYPE; break;
        case 'L': elemCls = getClass(inner + 1, end); break;
        default: break;
        }

        int dimension = inner - begin;
        // create 0 x 0 ... array and get class from that
        int[] dimArray = new int[dimension];
        tmp.add(java.lang.reflect.Array.newInstance(elemCls, dimArray).getClass());
      }

      protected Class getClass(int begin, int end) {
         String className = getClassName(begin, end);
         try {
            return Class.forName(className, true, cl);
         } catch (Exception e) {
            if (DEBUG) {
               System.err.println("Can't load class " + className);
            }
            throw new RuntimeException(e);
         }
      }

      protected String getClassName(int begin, int end) {
         StringBuffer buf = new StringBuffer();
         for (int i = begin; i < end; i++) {
            char c = (char) (_signature.getByteAt(i) & 0xFF);
            if (c == '/') {
               buf.append('.');
            } else {
               buf.append(c);
            }
         }
         return buf.toString();
      }

      protected int arrayInnerBegin(int begin) {
         while (_signature.getByteAt(begin) == '[') {
           ++begin;
         }
         return begin;
      }

      public int getNumParams() {
         return tmp.size();
      }

      public Enumeration getParamTypes() {
         return tmp.elements();
      }
   }

   protected Class[] getParamTypes(Symbol signature) {
      SignatureParser sp = new SignatureParser(signature);
      sp.iterateParameters();
      Class result[] = new Class[sp.getNumParams()];
      Enumeration e = sp.getParamTypes();
      int i = 0;
      while (e.hasMoreElements()) {
         result[i] = (Class) e.nextElement();
         i++;
      }
      return result;
   }
}