Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.7.0
-
Fix Version/s: 1.7.2, 1.8-beta-1
-
Component/s: None
-
Labels:None
-
Environment:Any, I guess.
I'm using Sun's Java6 on Linux.
-
Testcase included:yes
-
Number of attachments :
Description
I just discovered the @Immutable annotation and migrated some of my classes to it. Unfortunately, I realized that the behavior of the constructor changes slightly: For ordinary groovy beans, I used to get a MissingPropertyException when specifying a named parameter for a non-existing property. For @Immutable groovy beans, the parameter is silently ignored.
Here an example which shows the error:
@Immutable class ImmutablePerson {
String name
}
class Person {
String name
}
Person p = new Person(name: "uli"); // works fine
assert "uli" == p.name;
ImmutablePerson ip = new ImmutablePerson(name: "uli"); // works fine, too
assert "uli" == ip.name;
try {
Person p2 = new Person(name: "uli", lastname: "heller"); // throws an exception, fine
assert false;
} catch (MissingPropertyException mpe) {
assert true;
}
try {
ImmutablePerson ip2 = new ImmutablePerson(name: "uli", lastname: "heller"); // does not throw an exception
assert false; // ... so it fails within this assertion
} catch (MissingPropertyException mpe) {
assert true;
}
A groovy script with some assertions which fail due to missing MissingPropertyException.