Eclipse 直到运行时才报告错误

Eclipse doesn't report errors until runtime

我试图做一些乱七八糟的把戏来携带一个 IMarker 一个 ProblemDescriptor 对象。

ProblemDescriptor problem = new ProblemDescriptor(... my arguments...); marker.setAttribute("PROBLEM_DESCRIPTOR", problem);

稍后我想检查是否设置了属性,利用它的信息。

开发时没有报告错误,但在运行时出现错误:

The attribute value type is com.localhost.problems.ProblemDescription and expected is one of java.lang.String, Boolean, Integer

它是该代码中的特殊 case/a 错误实现,还是我应该习惯于仅在运行时报告的那些类型的错误?

确保您正确调用了您的方法。该错误看起来您正在传递

com.localhost.problems.ProblemDescription 

到一个期待其他东西的方法。

...省略参数没有帮助

您使用的setAttribute方法是

public void setAttribute(String attributeName, Object value)

由于第二个参数是 Object 无法在编译时检查正确性,但是 Javadoc 明确指出:

Sets the attribute with the given name. The value must be null or an instance of one of the following classes: String, Integer, or Boolean. If the value is null, the attribute is considered to be undefined.

The attribute value cannot be a String whose UTF encoding exceeds 65535 bytes. On persistent markers this limit is enforced by an assertion.

另一种设计是将其替换为具有 StringIntegerBoolean 第二个参数的 3 种方法,但 API 设计者决定不这样做那。