summaryrefslogtreecommitdiffstats
path: root/tests/bugs/NoByteToInt.java
blob: b60faf9d5bbc20797699eb2cc81ba90cbec6ac4c (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
//
// class NoByteToInt {
//
//	static final byte DEFAULT_MODE = 0;
//    static final byte RECORDING = 2;
//    
//	static byte mode = DEFAULT_MODE;
//	
//	public static void main (String[] args) {
//		mode = RECORDING;
//	}
//	
//}
//
// privileged aspect LoggingControl {
//	
//	/* ERROR */
//	pointcut startRecording1 (int newMode) :
//		set(byte NoByteToInt.mode) && args(newMode) && if(newMode != 5);
//
//	after () returning : startRecording1 (*) {
//		
//	}
//
////	/* OK */
////	pointcut startRecording2 (byte newMode) :
////		set(byte NoByteToInt.mode) && args(newMode) && if(newMode == 
////NoByteToInt.RECORDING);
////
////	after () returning : startRecording2 (*) {
////		
////	}
//
//	/* OK */
//	pointcut startRecording3 (int newMode) :
//		set(byte NoByteToInt.mode) && args(newMode);
//
//	after (int newMode) returning : startRecording3 (newMode) {
//		if (newMode == NoByteToInt.RECORDING) {
//			
//		}
//	}
//}
//
public class NoByteToInt {
    
	static byte mode;
	
	public static void main (String[] args) {
		setByte();
		setChar();
		setShort();
	}
		
	public static void setByte() {
		mode = 0;
		mode = 2;
		mode = 127;
	}
	
	static char c;
	
	public static void setChar() {
		c = 'A';
		c = 'B';
		c = 'C';
	}

	static short s;
	
	public static void setShort() {
		s = 1;
		s = 32767;
	}
	
}

 privileged aspect LoggingControl {
	
	/* ERROR */
	pointcut startRecording1 (int newMode) :
		set(byte NoByteToInt.mode) && args(newMode)  && if(newMode!=3);

	after (int n) returning : startRecording1 (n) {
		System.err.println("[b"+n+"]");
	}
	
	pointcut startRecording2 (int newMode) :
		set(char NoByteToInt.c) && args(newMode) && if(newMode!=3);

	after (int n) returning : startRecording2 (n) {
		System.err.println("[c"+n+"]");
	}
	
	pointcut startRecording3 (int newMode) :
		set(short NoByteToInt.s) && args(newMode) && if(newMode!=3);

	after (int n) returning : startRecording3 (n) {
		System.err.println("[s"+n+"]");
	}


}