John Doe
John Doe

Reputation: 1138

Eclipse doesn't report errors until runtime

I was trying to do some messy tricks to carry in an IMarker a ProblemDescriptor object.

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

Later on I wanted to check if the attribute is set, make use of the informations from it.

The error is not reported while developing but at runtime I get the error:

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

Is it a special case/a bad implementation in that code or I should get used with those kinds of errors reported only at runtime?

Upvotes: 0

Views: 40

Answers (2)

greg-449
greg-449

Reputation: 111142

The setAttribute method you are using is

public void setAttribute(String attributeName, Object value)

Since the second argument is Object no check for correctness can be done at compile time, however the Javadoc for this clearly says:

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.

An alternative design would have been to replace this with 3 methods with a String, Integer and Boolean second argument but the API designers decided not to do that.

Upvotes: 1

Nathan
Nathan

Reputation: 96

Make sure you're calling your method correctly. That error looks like you are passing

com.localhost.problems.ProblemDescription 

To a method that is expecting something else.

... leaving out the arguments isn't helping

Upvotes: 0

Related Questions