| Summary: | Figure.getBounds() doesn't make a defensive copy | ||
|---|---|---|---|
| Product: | [Tools] GEF | Reporter: | Mark Levison <mark.levison> |
| Component: | GEF-Legacy Draw2d | Assignee: | gef-inbox <gef-inbox> |
| Status: | RESOLVED INVALID | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | ||
| Version: | 3.2 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
|
Description
Mark Levison
All of the examples do Figure.getBounds().getCopy(). I'm more than a bit surprised - however if thats the standard - I guess I will have to implement SafeFigure - with defensive getters. The JavaDoc for Figure.getBounds() specifically says: "callers of this method must not modify the returned Rectangle." Figure.getBounds() gets invoked a lot, often during painting (which needs to be quick). And it's not always modified. Essentially, this is a trade-off between performance and defense(?). We chose performance, which makes sense for a framework. Pratik - thanks for the comment. I will ask only one more question did anyone prove (using a profiler) that the defensive copy of Rectangle was really expensive? Since Java 1.3/1.4 I'm surprised how good the GC has become at making it very very cheap (effectively free) to make defensive copies. So I wonder if this was a premature optimization. This all came up because I got burned - by accidentally modifying a Rectangle and that made me look at the source. > expensive? Since Java 1.3/1.4 I'm surprised how good the GC has become at
> making it very very cheap (effectively free) to make defensive copies. So I
> wonder if this was a premature optimization.
I suppose you might say that. The optimization was done "pre" the JVMs becoming "mature". Java 1.2 was the original target platform.
|