RFR: 6510914: JScrollBar.getMinimumSize() breaks the contract of JComponent.setMinimumSize() [v9]

Phil Race prr at openjdk.org
Mon Jan 22 21:30:34 UTC 2024


On Fri, 19 Jan 2024 04:48:40 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> javadoc contract for JComponent.setMinimumSize(Dimension) states:
>> 
>> "Sets the minimum size of this component to a constant value. Subsequent calls to getMinimumSize will always return this value..."
>> 
>> However, JScrollBar overrides getMinimumSize() and breaks this contract - it always returns a minimum size derived from the preferred size even if you have previously called setMinimumSize()
>> 
>> Fix is made to check if mnimumSize is set and if so, honour it..
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   javadoc updated

Changes requested by prr (Reviewer).

src/java.desktop/share/classes/javax/swing/JScrollBar.java line 773:

> 771:      * Unlike most components, JScrollBar will derive the maximum size from
> 772:      * the preferred size in one axis and a fixed maximum size in the other
> 773:      * unless otherwise set by the user.

that last line (unless ...) needs to go if we adopt what I suggest below

src/java.desktop/share/classes/javax/swing/JScrollBar.java line 789:

> 787:      *
> 788:      * @return the value of the {@code minimumSize} property if set by user
> 789:      *         or if not set, minimum size derived from

Seems we are not there yet. What is in this PR now is internally inconsistent.
It adopts doc on set*Size that reads as if get*Size will always ignore the super-class contract,
but on the get*Size methods we have new doc and implementation that actually in large part honours it.
One of these needs to change and then the CSR needs to match.

So, revisiting old ground, ie we've been back and forth on this.
we can keep the current PR code which is "if the user calls set*Size, then honour it, accepting the low risk, OR
we can keep the long standing behaviour, which is as near as we can get to no risk.

I'm still a bit on the fence, but I think I never want to hear about JScrollBar size again, :-)
So can we delete the new code in the get*Size methods and copy some of the wording from set*
     *JScrollBar will derive the maximum size from
      * the preferred size in one axis and a fixed maximum size in the other
     
then the return doc can reduce to
@ return the minimum size calculated as described above.

-------------

PR Review: https://git.openjdk.org/jdk/pull/15325#pullrequestreview-1837300085
PR Review Comment: https://git.openjdk.org/jdk/pull/15325#discussion_r1462420459
PR Review Comment: https://git.openjdk.org/jdk/pull/15325#discussion_r1462419893


More information about the client-libs-dev mailing list