--- old/src/java.desktop/windows/native/libawt/windows/awt_List.cpp 2018-11-05 21:01:22.970453042 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/awt_List.cpp 2018-11-05 21:01:22.494215042 +0530 @@ -478,16 +478,23 @@ MsgRouting AwtList::HandleEvent(MSG *msg, BOOL synthetic) { if (IsFocusingMouseMessage(msg)) { - LONG item = static_cast(SendListMessage(LB_ITEMFROMPOINT, 0, msg->lParam)); - if (item != LB_ERR) { - if (isMultiSelect) { - if (IsItemSelected(item)) { - Deselect(item); + LONG count = GetCount(); + if (count > 0) { + LONG item = static_cast(SendListMessage(LB_ITEMFROMPOINT, 0, msg->lParam)); + item = LOWORD(item); + if (SendListMessage(LB_GETTOPINDEX, 0, 0) > item) { + item = (count / max_index) * max_index + item + 1; + } + if (item < count) { + if (isMultiSelect) { + if (IsItemSelected(item)) { + Deselect(item); + } else { + Select(item); + } } else { Select(item); } - } else { - Select(item); } } delete msg; --- old/src/java.desktop/windows/native/libawt/windows/awt_List.h 2018-11-05 21:01:23.806871042 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/awt_List.h 2018-11-05 21:01:23.354645042 +0530 @@ -27,7 +27,7 @@ #define AWT_LIST_H #include "awt_Component.h" - +#include #include "sun_awt_windows_WListPeer.h" @@ -37,6 +37,7 @@ class AwtList : public AwtComponent { public: + const UINT max_index = std::pow(2, (sizeof(WORD) * 8)) - 1; AwtList(); virtual ~AwtList(); --- old/test/jdk/java/awt/List/EmptyListEventTest/EmptyListEventTest.java 2018-11-05 21:01:24.663299042 +0530 +++ new/test/jdk/java/awt/List/EmptyListEventTest/EmptyListEventTest.java 2018-11-05 21:01:24.215075042 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2018, 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 @@ -24,7 +24,7 @@ /* * @test * @key headful - * @bug 6366126 + * @bug 6366126 8198000 * @summary List throws ArrayIndexOutOfBoundsException when pressing ENTER after removing all the items, Win32 * @author Dmitry Cherepanov area=awt.list * @run main EmptyListEventTest