8369455: XAWT: List.getSelectedItem may throw ArrayIndexOutOfBoundsException

Reviewed-by: prr, azvegint, aivanov
This commit is contained in:
Sergey Bylokhov 2026-05-07 23:41:19 +00:00
parent ffc16bd40d
commit f5aae68315
3 changed files with 8 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1233,10 +1233,12 @@ final class XListPeer extends XComponentPeer implements ListPeer, XScrollbarClie
*/
@Override
public void select(int index) {
// Programmatic select() should also set the focus index
setFocusIndex(index);
repaint(PAINT_FOCUS);
selectItem(index);
if (index >= 0 && index < items.size()) {
// Programmatic select() should also set the focus index
setFocusIndex(index);
repaint(PAINT_FOCUS);
selectItem(index);
}
}
/**

View File

@ -151,7 +151,6 @@ java/awt/grab/EmbeddedFrameTest1/EmbeddedFrameTest1.java 7080150 macosx-all
java/awt/event/InputEvent/EventWhenTest/EventWhenTest.java 8168646 generic-all
java/awt/List/KeyEventsTest/KeyEventsTest.java 8201307 linux-all
java/awt/List/NoEvents/ProgrammaticChange.java 8201307 linux-all
java/awt/List/ListSelection/SelectInvalidTest.java 8369455 linux-all
java/awt/Paint/ListRepaint.java 8201307 linux-all
java/awt/Mixing/AWT_Mixing/OpaqueOverlappingChoice.java 8048171 generic-all
java/awt/Mixing/AWT_Mixing/JInternalFrameMoveOverlapping.java 6986109 windows-all

View File

@ -32,7 +32,7 @@ import static jdk.test.lib.Asserts.assertTrue;
/**
* @test
* @bug 8369327
* @bug 8369327 8369455
* @summary Test awt list selection of invalid indexes
* @key headful
* @library /test/lib