001: /***
002: * ASM tests
003: * Copyright (c) 2002-2005 France Telecom
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: * 1. Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: * 2. Redistributions in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in the
013: * documentation and/or other materials provided with the distribution.
014: * 3. Neither the name of the copyright holders nor the names of its
015: * contributors may be used to endorse or promote products derived from
016: * this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
028: * THE POSSIBILITY OF SUCH DAMAGE.
029: */package org.objectweb.asm.util;
030:
031: import java.io.IOException;
032: import java.io.PrintWriter;
033:
034: import junit.framework.TestCase;
035:
036: import org.objectweb.asm.AnnotationVisitor;
037: import org.objectweb.asm.ClassAdapter;
038: import org.objectweb.asm.ClassReader;
039: import org.objectweb.asm.ClassVisitor;
040: import org.objectweb.asm.ClassWriter;
041: import org.objectweb.asm.FieldVisitor;
042: import org.objectweb.asm.Label;
043: import org.objectweb.asm.MethodAdapter;
044: import org.objectweb.asm.MethodVisitor;
045: import org.objectweb.asm.Opcodes;
046: import org.objectweb.asm.attrs.Comment;
047: import org.objectweb.asm.commons.EmptyVisitor;
048:
049: public class CheckClassAdapterUnitTest extends TestCase implements
050: Opcodes {
051:
052: public void testCheckClassVisitor() throws Exception {
053: String s = getClass().getName();
054: CheckClassAdapter.main(new String[0]);
055: CheckClassAdapter.main(new String[] { s });
056: CheckClassAdapter
057: .main(new String[] { "output/test/cases/Interface.class" });
058: }
059:
060: public void testVerifyValidClass() throws Exception {
061: ClassReader cr = new ClassReader(getClass().getName());
062: CheckClassAdapter.verify(cr, true, new PrintWriter(System.err));
063: }
064:
065: public void testVerifyInvalidClass() {
066: ClassWriter cw = new ClassWriter(0);
067: cw.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
068: MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "m", "()V", null,
069: null);
070: mv.visitCode();
071: mv.visitVarInsn(ALOAD, 0);
072: mv.visitVarInsn(ISTORE, 30);
073: mv.visitInsn(RETURN);
074: mv.visitMaxs(1, 31);
075: mv.visitEnd();
076: cw.visitEnd();
077: ClassReader cr = new ClassReader(cw.toByteArray());
078: CheckClassAdapter.verify(cr, true, new PrintWriter(System.err));
079: }
080:
081: public void testIllegalClassAccessFlag() {
082: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
083: try {
084: cv
085: .visit(V1_1, 1 << 20, "C", null,
086: "java/lang/Object", null);
087: fail();
088: } catch (Exception e) {
089: }
090: }
091:
092: public void testIllegalSuperClass() {
093: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
094: try {
095: cv.visit(V1_1, ACC_PUBLIC, "java/lang/Object", null,
096: "java/lang/Object", null);
097: fail();
098: } catch (Exception e) {
099: }
100: }
101:
102: public void testIllegalInterfaceSuperClass() {
103: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
104: try {
105: cv.visit(V1_1, ACC_INTERFACE, "I", null, "C", null);
106: fail();
107: } catch (Exception e) {
108: }
109: }
110:
111: public void testIllegalClassSignature() {
112: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
113: try {
114: cv.visit(V1_1, ACC_PUBLIC, "C", "LC;I", "java/lang/Object",
115: null);
116: fail();
117: } catch (Exception e) {
118: }
119: }
120:
121: public void testIllegalClassAccessFlagSet() {
122: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
123: try {
124: cv.visit(V1_1, ACC_FINAL + ACC_ABSTRACT, "C", null,
125: "java/lang/Object", null);
126: fail();
127: } catch (Exception e) {
128: }
129: }
130:
131: public void testIllegalClassMemberVisitBeforeStart() {
132: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
133: try {
134: cv.visitSource(null, null);
135: fail();
136: } catch (Exception e) {
137: }
138: }
139:
140: public void testIllegalClassAttribute() {
141: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
142: cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
143: try {
144: cv.visitAttribute(null);
145: fail();
146: } catch (Exception e) {
147: }
148: }
149:
150: public void testIllegalMultipleVisitCalls() {
151: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
152: cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
153: try {
154: cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object",
155: null);
156: fail();
157: } catch (Exception e) {
158: }
159: }
160:
161: public void testIllegalMultipleVisitSourceCalls() {
162: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
163: cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
164: cv.visitSource(null, null);
165: try {
166: cv.visitSource(null, null);
167: fail();
168: } catch (Exception e) {
169: }
170: }
171:
172: public void testIllegalOuterClassName() {
173: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
174: cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
175: try {
176: cv.visitOuterClass(null, null, null);
177: fail();
178: } catch (Exception e) {
179: }
180: }
181:
182: public void testIllegalMultipleVisitOuterClassCalls() {
183: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
184: cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
185: cv.visitOuterClass("name", null, null);
186: try {
187: cv.visitOuterClass(null, null, null);
188: fail();
189: } catch (Exception e) {
190: }
191: }
192:
193: public void testIllegalFieldAccessFlagSet() {
194: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
195: cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
196: try {
197: cv.visitField(ACC_PUBLIC + ACC_PRIVATE, "i", "I", null,
198: null);
199: fail();
200: } catch (Exception e) {
201: }
202: }
203:
204: public void testIllegalFieldSignature() {
205: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
206: cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
207: try {
208: cv.visitField(ACC_PUBLIC, "i", "I", "L;", null);
209: fail();
210: } catch (Exception e) {
211: }
212: try {
213: cv.visitField(ACC_PUBLIC, "i", "I", "LC+", null);
214: fail();
215: } catch (Exception e) {
216: }
217: try {
218: cv.visitField(ACC_PUBLIC, "i", "I", "LC;I", null);
219: fail();
220: } catch (Exception e) {
221: }
222: }
223:
224: public void testIllegalClassMemberVisitAfterEnd() {
225: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
226: cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
227: cv.visitEnd();
228: try {
229: cv.visitSource(null, null);
230: fail();
231: } catch (Exception e) {
232: }
233: }
234:
235: public void testIllegalFieldMemberVisitAfterEnd() {
236: FieldVisitor fv = new CheckFieldAdapter(new EmptyVisitor());
237: fv.visitEnd();
238: try {
239: fv.visitAttribute(new Comment());
240: fail();
241: } catch (Exception e) {
242: }
243: }
244:
245: public void testIllegalFieldAttribute() {
246: FieldVisitor fv = new CheckFieldAdapter(new EmptyVisitor());
247: try {
248: fv.visitAttribute(null);
249: fail();
250: } catch (Exception e) {
251: }
252: }
253:
254: public void testIllegalAnnotationDesc() {
255: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
256: try {
257: mv.visitParameterAnnotation(0, "'", true);
258: fail();
259: } catch (Exception e) {
260: }
261: }
262:
263: public void testIllegalAnnotationName() {
264: AnnotationVisitor av = new CheckAnnotationAdapter(
265: new EmptyVisitor());
266: try {
267: av.visit(null, new Integer(0));
268: fail();
269: } catch (Exception e) {
270: }
271: }
272:
273: public void testIllegalAnnotationValue() {
274: AnnotationVisitor av = new CheckAnnotationAdapter(
275: new EmptyVisitor());
276: try {
277: av.visit("name", new Object());
278: fail();
279: } catch (Exception e) {
280: }
281: }
282:
283: public void testIllegalAnnotationEnumValue() {
284: AnnotationVisitor av = new CheckAnnotationAdapter(
285: new EmptyVisitor());
286: try {
287: av.visitEnum("name", "Lpkg/Enum;", null);
288: fail();
289: } catch (Exception e) {
290: }
291: }
292:
293: public void testIllegalAnnotationValueAfterEnd() {
294: AnnotationVisitor av = new CheckAnnotationAdapter(
295: new EmptyVisitor());
296: av.visitEnd();
297: try {
298: av.visit("name", new Integer(0));
299: fail();
300: } catch (Exception e) {
301: }
302: }
303:
304: public void testIllegalMethodMemberVisitAfterEnd() {
305: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
306: mv.visitEnd();
307: try {
308: mv.visitAttribute(new Comment());
309: fail();
310: } catch (Exception e) {
311: }
312: }
313:
314: public void testIllegalMethodAttribute() {
315: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
316: try {
317: mv.visitAttribute(null);
318: fail();
319: } catch (Exception e) {
320: }
321: }
322:
323: public void testIllegalMethodSignature() {
324: ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
325: cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
326: try {
327: cv.visitMethod(ACC_PUBLIC, "m", "()V",
328: "<T::LI.J<*+LA;>;>()V^LA;X", null);
329: fail();
330: } catch (Exception e) {
331: }
332: }
333:
334: public void testIllegalMethodInsnVisitBeforeStart() {
335: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
336: try {
337: mv.visitInsn(NOP);
338: fail();
339: } catch (Exception e) {
340: }
341: }
342:
343: public void testIllegalFrameType() {
344: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
345: mv.visitCode();
346: try {
347: mv.visitFrame(123, 0, null, 0, null);
348: fail();
349: } catch (Exception e) {
350: }
351: }
352:
353: public void testIllegalFrameLocalCount() {
354: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
355: mv.visitCode();
356: try {
357: mv.visitFrame(F_SAME, 1, new Object[] { INTEGER }, 0, null);
358: fail();
359: } catch (Exception e) {
360: }
361: }
362:
363: public void testIllegalFrameStackCount() {
364: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
365: mv.visitCode();
366: try {
367: mv.visitFrame(F_SAME, 0, null, 1, new Object[] { INTEGER });
368: fail();
369: } catch (Exception e) {
370: }
371: }
372:
373: public void testIllegalFrameLocalArray() {
374: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
375: mv.visitCode();
376: try {
377: mv.visitFrame(F_APPEND, 1, new Object[0], 0, null);
378: fail();
379: } catch (Exception e) {
380: }
381: }
382:
383: public void testIllegalFrameStackArray() {
384: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
385: mv.visitCode();
386: try {
387: mv.visitFrame(F_SAME1, 0, null, 1, new Object[0]);
388: fail();
389: } catch (Exception e) {
390: }
391: }
392:
393: public void testIllegalFrameValue() {
394: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
395: mv.visitCode();
396: try {
397: mv.visitFrame(F_FULL, 1, new Object[] { "LC;" }, 0, null);
398: fail();
399: } catch (Exception e) {
400: }
401: try {
402: mv.visitFrame(F_FULL, 1, new Object[] { new Integer(0) },
403: 0, null);
404: fail();
405: } catch (Exception e) {
406: }
407: }
408:
409: public void testIllegalMethodInsn() {
410: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
411: mv.visitCode();
412: try {
413: mv.visitInsn(-1);
414: fail();
415: } catch (Exception e) {
416: }
417: }
418:
419: public void testIllegalByteInsnOperand() {
420: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
421: mv.visitCode();
422: try {
423: mv.visitIntInsn(BIPUSH, Integer.MAX_VALUE);
424: fail();
425: } catch (Exception e) {
426: }
427: }
428:
429: public void testIllegalShortInsnOperand() {
430: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
431: mv.visitCode();
432: try {
433: mv.visitIntInsn(SIPUSH, Integer.MAX_VALUE);
434: fail();
435: } catch (Exception e) {
436: }
437: }
438:
439: public void testIllegalVarInsnOperand() {
440: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
441: mv.visitCode();
442: try {
443: mv.visitVarInsn(ALOAD, -1);
444: fail();
445: } catch (Exception e) {
446: }
447: }
448:
449: public void testIllegalIntInsnOperand() {
450: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
451: mv.visitCode();
452: try {
453: mv.visitIntInsn(NEWARRAY, 0);
454: fail();
455: } catch (Exception e) {
456: }
457: }
458:
459: public void testIllegalTypeInsnOperand() {
460: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
461: mv.visitCode();
462: try {
463: mv.visitTypeInsn(NEW, "[I");
464: fail();
465: } catch (Exception e) {
466: }
467: }
468:
469: public void testIllegalLabelInsnOperand() {
470: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
471: mv.visitCode();
472: Label l = new Label();
473: mv.visitLabel(l);
474: try {
475: mv.visitLabel(l);
476: fail();
477: } catch (Exception e) {
478: }
479: }
480:
481: public void testIllegalDebugLabelUse() throws IOException {
482: ClassReader cr = new ClassReader("java.lang.Object");
483: ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS);
484: cr.accept(new ClassAdapter(cw) {
485: public MethodVisitor visitMethod(int access, String name,
486: String desc, String signature, String[] exceptions) {
487: final MethodVisitor next = cv.visitMethod(access, name,
488: desc, signature, exceptions);
489: if (next == null) {
490: return next;
491: }
492: return new MethodAdapter(new CheckMethodAdapter(next)) {
493: private Label entryLabel = null;
494:
495: public void visitLabel(Label label) {
496: if (entryLabel == null) {
497: entryLabel = label;
498: }
499: mv.visitLabel(label);
500: }
501:
502: public void visitMaxs(int maxStack, int maxLocals) {
503: Label unwindhandler = new Label();
504: mv.visitLabel(unwindhandler);
505: mv.visitInsn(Opcodes.ATHROW); // rethrow
506: mv.visitTryCatchBlock(entryLabel,
507: unwindhandler, unwindhandler, null);
508: mv.visitMaxs(maxStack, maxLocals);
509: }
510: };
511: }
512: }, ClassReader.EXPAND_FRAMES);
513: }
514:
515: public void testIllegalTableSwitchParameters1() {
516: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
517: mv.visitCode();
518: try {
519: mv.visitTableSwitchInsn(1, 0, new Label(), new Label[0]);
520: fail();
521: } catch (Exception e) {
522: }
523: }
524:
525: public void testIllegalTableSwitchParameters2() {
526: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
527: mv.visitCode();
528: try {
529: mv.visitTableSwitchInsn(0, 1, null, new Label[0]);
530: fail();
531: } catch (Exception e) {
532: }
533: }
534:
535: public void testIllegalTableSwitchParameters3() {
536: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
537: mv.visitCode();
538: try {
539: mv.visitTableSwitchInsn(0, 1, new Label(), null);
540: fail();
541: } catch (Exception e) {
542: }
543: }
544:
545: public void testIllegalTableSwitchParameters4() {
546: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
547: mv.visitCode();
548: try {
549: mv.visitTableSwitchInsn(0, 1, new Label(), new Label[0]);
550: fail();
551: } catch (Exception e) {
552: }
553: }
554:
555: public void testIllegalLookupSwitchParameters1() {
556: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
557: mv.visitCode();
558: try {
559: mv.visitLookupSwitchInsn(new Label(), null, new Label[0]);
560: fail();
561: } catch (Exception e) {
562: }
563: }
564:
565: public void testIllegalLookupSwitchParameters2() {
566: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
567: mv.visitCode();
568: try {
569: mv.visitLookupSwitchInsn(new Label(), new int[0], null);
570: fail();
571: } catch (Exception e) {
572: }
573: }
574:
575: public void testIllegalLookupSwitchParameters3() {
576: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
577: mv.visitCode();
578: try {
579: mv.visitLookupSwitchInsn(new Label(), new int[0],
580: new Label[1]);
581: fail();
582: } catch (Exception e) {
583: }
584: }
585:
586: public void testIllegalFieldInsnNullOwner() {
587: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
588: mv.visitCode();
589: try {
590: mv.visitFieldInsn(GETFIELD, null, "i", "I");
591: fail();
592: } catch (Exception e) {
593: }
594: }
595:
596: public void testIllegalFieldInsnOwner() {
597: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
598: mv.visitCode();
599: try {
600: mv.visitFieldInsn(GETFIELD, "-", "i", "I");
601: fail();
602: } catch (Exception e) {
603: }
604: }
605:
606: public void testIllegalFieldInsnNullName() {
607: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
608: mv.visitCode();
609: try {
610: mv.visitFieldInsn(GETFIELD, "C", null, "I");
611: fail();
612: } catch (Exception e) {
613: }
614: }
615:
616: public void testIllegalFieldInsnName() {
617: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
618: mv.visitCode();
619: try {
620: mv.visitFieldInsn(GETFIELD, "C", "-", "I");
621: fail();
622: } catch (Exception e) {
623: }
624: }
625:
626: public void testIllegalFieldInsnName2() {
627: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
628: mv.visitCode();
629:
630: try {
631: mv.visitFieldInsn(GETFIELD, "C", "a-", "I");
632: fail();
633: } catch (Exception e) {
634: }
635: }
636:
637: public void testIllegalFieldInsnNullDesc() {
638: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
639: mv.visitCode();
640: try {
641: mv.visitFieldInsn(GETFIELD, "C", "i", null);
642: fail();
643: } catch (Exception e) {
644: }
645: }
646:
647: public void testIllegalFieldInsnVoidDesc() {
648: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
649: mv.visitCode();
650: try {
651: mv.visitFieldInsn(GETFIELD, "C", "i", "V");
652: fail();
653: } catch (Exception e) {
654: }
655: }
656:
657: public void testIllegalFieldInsnPrimitiveDesc() {
658: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
659: mv.visitCode();
660: try {
661: mv.visitFieldInsn(GETFIELD, "C", "i", "II");
662: fail();
663: } catch (Exception e) {
664: }
665: }
666:
667: public void testIllegalFieldInsnArrayDesc() {
668: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
669: mv.visitCode();
670: try {
671: mv.visitFieldInsn(GETFIELD, "C", "i", "[");
672: fail();
673: } catch (Exception e) {
674: }
675: }
676:
677: public void testIllegalFieldInsnReferenceDesc() {
678: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
679: mv.visitCode();
680: try {
681: mv.visitFieldInsn(GETFIELD, "C", "i", "L");
682: fail();
683: } catch (Exception e) {
684: }
685: }
686:
687: public void testIllegalFieldInsnReferenceDesc2() {
688: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
689: mv.visitCode();
690: try {
691: mv.visitFieldInsn(GETFIELD, "C", "i", "L-;");
692: fail();
693: } catch (Exception e) {
694: }
695: }
696:
697: public void testIllegalMethodInsnNullName() {
698: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
699: mv.visitCode();
700: try {
701: mv.visitMethodInsn(INVOKEVIRTUAL, "C", null, "()V");
702: fail();
703: } catch (Exception e) {
704: }
705: }
706:
707: public void testIllegalMethodInsnName() {
708: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
709: mv.visitCode();
710: try {
711: mv.visitMethodInsn(INVOKEVIRTUAL, "C", "-", "()V");
712: fail();
713: } catch (Exception e) {
714: }
715: }
716:
717: public void testIllegalMethodInsnName2() {
718: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
719: mv.visitCode();
720: try {
721: mv.visitMethodInsn(INVOKEVIRTUAL, "C", "a-", "()V");
722: fail();
723: } catch (Exception e) {
724: }
725: }
726:
727: public void testIllegalMethodInsnNullDesc() {
728: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
729: mv.visitCode();
730: try {
731: mv.visitMethodInsn(INVOKEVIRTUAL, "C", "m", null);
732: fail();
733: } catch (Exception e) {
734: }
735: }
736:
737: public void testIllegalMethodInsnDesc() {
738: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
739: mv.visitCode();
740: try {
741: mv.visitMethodInsn(INVOKEVIRTUAL, "C", "m", "I");
742: fail();
743: } catch (Exception e) {
744: }
745: }
746:
747: public void testIllegalMethodInsnParameterDesc() {
748: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
749: mv.visitCode();
750: try {
751: mv.visitMethodInsn(INVOKEVIRTUAL, "C", "m", "(V)V");
752: fail();
753: } catch (Exception e) {
754: }
755: }
756:
757: public void testIllegalMethodInsnReturnDesc() {
758: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
759: mv.visitCode();
760: try {
761: mv.visitMethodInsn(INVOKEVIRTUAL, "C", "m", "()VV");
762: fail();
763: } catch (Exception e) {
764: }
765: }
766:
767: public void testIllegalLdcInsnOperand() {
768: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
769: mv.visitCode();
770: try {
771: mv.visitLdcInsn(new Object());
772: fail();
773: } catch (Exception e) {
774: }
775: }
776:
777: public void testIllegalMultiANewArrayDesc() {
778: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
779: mv.visitCode();
780: try {
781: mv.visitMultiANewArrayInsn("I", 1);
782: fail();
783: } catch (Exception e) {
784: }
785: }
786:
787: public void testIllegalMultiANewArrayDims() {
788: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
789: mv.visitCode();
790: try {
791: mv.visitMultiANewArrayInsn("[[I", 0);
792: fail();
793: } catch (Exception e) {
794: }
795: }
796:
797: public void testIllegalMultiANewArrayDims2() {
798: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
799: mv.visitCode();
800: try {
801: mv.visitMultiANewArrayInsn("[[I", 3);
802: fail();
803: } catch (Exception e) {
804: }
805: }
806:
807: public void testIllegalTryCatchBlock() {
808: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
809: mv.visitCode();
810: Label m = new Label();
811: Label n = new Label();
812: mv.visitLabel(m);
813: try {
814: mv.visitTryCatchBlock(m, n, n, null);
815: fail();
816: } catch (Exception e) {
817: }
818: try {
819: mv.visitTryCatchBlock(n, m, n, null);
820: fail();
821: } catch (Exception e) {
822: }
823: try {
824: mv.visitTryCatchBlock(n, n, m, null);
825: fail();
826: } catch (Exception e) {
827: }
828: }
829:
830: public void testIllegalLocalVariableLabels() {
831: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
832: mv.visitCode();
833: Label m = new Label();
834: Label n = new Label();
835: mv.visitLabel(n);
836: mv.visitInsn(NOP);
837: mv.visitLabel(m);
838: try {
839: mv.visitLocalVariable("i", "I", null, m, n, 0);
840: fail();
841: } catch (Exception e) {
842: }
843: }
844:
845: public void testIllegalLineNumerLabel() {
846: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
847: mv.visitCode();
848: try {
849: mv.visitLineNumber(0, new Label());
850: fail();
851: } catch (Exception e) {
852: }
853: }
854:
855: public void testIllegalInsnVisitAfterEnd() {
856: MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
857: mv.visitCode();
858: mv.visitMaxs(0, 0);
859: try {
860: mv.visitInsn(NOP);
861: fail();
862: } catch (Exception e) {
863: }
864: }
865: }
|