You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NoByteToInt.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // class NoByteToInt {
  3. //
  4. // static final byte DEFAULT_MODE = 0;
  5. // static final byte RECORDING = 2;
  6. //
  7. // static byte mode = DEFAULT_MODE;
  8. //
  9. // public static void main (String[] args) {
  10. // mode = RECORDING;
  11. // }
  12. //
  13. //}
  14. //
  15. // privileged aspect LoggingControl {
  16. //
  17. // /* ERROR */
  18. // pointcut startRecording1 (int newMode) :
  19. // set(byte NoByteToInt.mode) && args(newMode) && if(newMode != 5);
  20. //
  21. // after () returning : startRecording1 (*) {
  22. //
  23. // }
  24. //
  25. //// /* OK */
  26. //// pointcut startRecording2 (byte newMode) :
  27. //// set(byte NoByteToInt.mode) && args(newMode) && if(newMode ==
  28. ////NoByteToInt.RECORDING);
  29. ////
  30. //// after () returning : startRecording2 (*) {
  31. ////
  32. //// }
  33. //
  34. // /* OK */
  35. // pointcut startRecording3 (int newMode) :
  36. // set(byte NoByteToInt.mode) && args(newMode);
  37. //
  38. // after (int newMode) returning : startRecording3 (newMode) {
  39. // if (newMode == NoByteToInt.RECORDING) {
  40. //
  41. // }
  42. // }
  43. //}
  44. //
  45. public class NoByteToInt {
  46. static byte mode;
  47. public static void main (String[] args) {
  48. setByte();
  49. setChar();
  50. setShort();
  51. }
  52. public static void setByte() {
  53. mode = 0;
  54. mode = 2;
  55. mode = 127;
  56. }
  57. static char c;
  58. public static void setChar() {
  59. c = 'A';
  60. c = 'B';
  61. c = 'C';
  62. }
  63. static short s;
  64. public static void setShort() {
  65. s = 1;
  66. s = 32767;
  67. }
  68. }
  69. privileged aspect LoggingControl {
  70. /* ERROR */
  71. pointcut startRecording1 (int newMode) :
  72. set(byte NoByteToInt.mode) && args(newMode) && if(newMode!=3);
  73. after (int n) returning : startRecording1 (n) {
  74. System.err.println("[b"+n+"]");
  75. }
  76. pointcut startRecording2 (int newMode) :
  77. set(char NoByteToInt.c) && args(newMode) && if(newMode!=3);
  78. after (int n) returning : startRecording2 (n) {
  79. System.err.println("[c"+n+"]");
  80. }
  81. pointcut startRecording3 (int newMode) :
  82. set(short NoByteToInt.s) && args(newMode) && if(newMode!=3);
  83. after (int n) returning : startRecording3 (n) {
  84. System.err.println("[s"+n+"]");
  85. }
  86. }