Hendrik Maryns said:
Oliver Wong schreef:
If I remember right from my OO classes, declaring an exception can be
thrown *never* implies it *must* be thrown in specific cases, except
explicitly stated. So this indeed is ?not a bug?.
The exact wording of the 1.5 Javadocs is:
<quote>
Throws:
IllegalArgumentException - if the owner's GraphicsConfiguration is not
from a screen device
IllegalArgumentException - if owner is null. This exception is always
thrown when GraphicsEnvironment.isHeadless() returns true.
</quote>
To me, "Throws" means "I guarantee I will throw it under these
conditions, or else I am not fufilling my contract". If they instead meant
"I may or may not throw", I would have expected wording similar to what is
seen, for example, in the docs for the LinkedList class:
<quote>
The iterators returned by the this class's iterator and listIterator methods
are fail-fast: if the list is structurally modified at any time after the
iterator is created, in any way except through the Iterator's own remove or
add methods, the iterator will throw a ConcurrentModificationException.
Thus, in the face of concurrent modification, the iterator fails quickly and
cleanly, rather than risking arbitrary, non-deterministic behavior at an
undetermined time in the future.
Note that the fail-fast behavior of an iterator cannot be guaranteed as it
is, generally speaking, impossible to make any hard guarantees in the
presence of unsynchronized concurrent modification. Fail-fast iterators
throw ConcurrentModificationException on a best-effort basis. Therefore, it
would be wrong to write a program that depended on this exception for its
correctness: the fail-fast behavior of iterators should be used only to
detect bugs.
</quote>
- Oliver