1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.bcel.classfile;
21
22 import static org.junit.jupiter.api.Assertions.assertThrows;
23
24 import java.io.ByteArrayInputStream;
25 import java.io.DataInputStream;
26
27 import org.junit.jupiter.api.Test;
28
29
30
31
32 public class AttributeTest {
33
34 @Test
35 public void testReadAttributeInvalidName() {
36 final DataInputStream dataInput = new DataInputStream(new ByteArrayInputStream(new byte[] { 0, 0, 0, 0, 0 }));
37 final Constant[] constants = new Constant[1];
38 final ConstantPool constantPool = new ConstantPool(constants);
39 assertThrows(ClassFormatException.class, () -> Attribute.readAttribute(dataInput, constantPool));
40 }
41
42 @Test
43 public void testReadAttributeNegativeLength() {
44 final DataInputStream dataInput = new DataInputStream(new ByteArrayInputStream(new byte[] { 0, 0, 0, 0, -1 }));
45 final Constant[] constants = new Constant[1];
46 final ConstantPool constantPool = new ConstantPool(constants);
47 assertThrows(ClassFormatException.class, () -> Attribute.readAttribute(dataInput, constantPool));
48 }
49 }