選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CannotCompileException.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. Alternatively, the contents of this file may be used under
  8. * the terms of the GNU Lesser General Public License Version 2.1 or later,
  9. * or the Apache License Version 2.0.
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. */
  16. package javassist;
  17. import javassist.compiler.CompileError;
  18. /**
  19. * Thrown when bytecode transformation has failed.
  20. */
  21. public class CannotCompileException extends Exception {
  22. /** default serialVersionUID */
  23. private static final long serialVersionUID = 1L;
  24. private Throwable myCause;
  25. /**
  26. * Gets the cause of this throwable.
  27. * It is for JDK 1.3 compatibility.
  28. */
  29. @Override
  30. public synchronized Throwable getCause() {
  31. return (myCause == this ? null : myCause);
  32. }
  33. /**
  34. * Initializes the cause of this throwable.
  35. * It is for JDK 1.3 compatibility.
  36. */
  37. @Override
  38. public synchronized Throwable initCause(Throwable cause) {
  39. myCause = cause;
  40. return this;
  41. }
  42. private String message;
  43. /**
  44. * Gets a long message if it is available.
  45. */
  46. public String getReason() {
  47. if (message != null)
  48. return message;
  49. return this.toString();
  50. }
  51. /**
  52. * Constructs a CannotCompileException with a message.
  53. *
  54. * @param msg the message.
  55. */
  56. public CannotCompileException(String msg) {
  57. super(msg);
  58. message = msg;
  59. initCause(null);
  60. }
  61. /**
  62. * Constructs a CannotCompileException with an <code>Exception</code>
  63. * representing the cause.
  64. *
  65. * @param e the cause.
  66. */
  67. public CannotCompileException(Throwable e) {
  68. super("by " + e.toString());
  69. message = null;
  70. initCause(e);
  71. }
  72. /**
  73. * Constructs a CannotCompileException with a detailed message
  74. * and an <code>Exception</code> representing the cause.
  75. *
  76. * @param msg the message.
  77. * @param e the cause.
  78. */
  79. public CannotCompileException(String msg, Throwable e) {
  80. this(msg);
  81. initCause(e);
  82. }
  83. /**
  84. * Constructs a CannotCompileException with a
  85. * <code>NotFoundException</code>.
  86. */
  87. public CannotCompileException(NotFoundException e) {
  88. this("cannot find " + e.getMessage(), e);
  89. }
  90. /**
  91. * Constructs a CannotCompileException with an <code>CompileError</code>.
  92. */
  93. public CannotCompileException(CompileError e) {
  94. this("[source error] " + e.getMessage(), e);
  95. }
  96. /**
  97. * Constructs a CannotCompileException
  98. * with a <code>ClassNotFoundException</code>.
  99. */
  100. public CannotCompileException(ClassNotFoundException e, String name) {
  101. this("cannot find " + name, e);
  102. }
  103. /**
  104. * Constructs a CannotCompileException with a ClassFormatError.
  105. */
  106. public CannotCompileException(ClassFormatError e, String name) {
  107. this("invalid class format: " + name, e);
  108. }
  109. }