From 91e7b0bd8ae86caa71b1012df40c62586749ce1e Mon Sep 17 00:00:00 2001 From: Harsha Wardhana B Date: Mon, 4 Jan 2016 13:49:11 +0100 Subject: [PATCH] 6744127: NullPointerException at com.sun.tools.jdi.EventRequestManagerImpl.request Reviewed-by: jbachorik, sspitsyn --- .../tools/jdi/EventRequestManagerImpl.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/EventRequestManagerImpl.java b/jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/EventRequestManagerImpl.java index 93c10f0b00f..6f928785255 100644 --- a/jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/EventRequestManagerImpl.java +++ b/jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/EventRequestManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -43,7 +43,7 @@ import java.util.*; class EventRequestManagerImpl extends MirrorImpl implements EventRequestManager { - List[] requestLists; + private final List[] requestLists; private static int methodExitEventCmd = 0; static int JDWPtoJDISuspendPolicy(byte jdwpPolicy) { @@ -83,7 +83,7 @@ class EventRequestManagerImpl extends MirrorImpl return System.identityHashCode(this); } - abstract class EventRequestImpl extends MirrorImpl implements EventRequest { + private abstract class EventRequestImpl extends MirrorImpl implements EventRequest { int id; /* @@ -734,7 +734,7 @@ class EventRequestManagerImpl extends MirrorImpl } requestLists = new List[highest+1]; for (int i=0; i <= highest; i++) { - requestLists[i] = new ArrayList<>(); + requestLists[i] = Collections.synchronizedList(new ArrayList<>()); } } @@ -933,22 +933,27 @@ class EventRequestManagerImpl extends MirrorImpl } List unmodifiableRequestList(int eventCmd) { - return Collections.unmodifiableList(requestList(eventCmd)); + // No need of explicit synchronization for requestList here. + // It is taken care internally by SynchronizedList class. + return Collections.unmodifiableList(new ArrayList<>(requestList(eventCmd))); } EventRequest request(int eventCmd, int requestId) { List rl = requestList(eventCmd); - for (int i = rl.size() - 1; i >= 0; i--) { - EventRequestImpl er = (EventRequestImpl)rl.get(i); - if (er.id == requestId) { - return er; + synchronized(rl) { // Refer Collections.synchronizedList javadoc. + Iterator itr = rl.iterator(); + while (itr.hasNext()){ + EventRequestImpl er = (EventRequestImpl)itr.next(); + if (er.id == requestId) + return er; } } return null; } - List requestList(int eventCmd) { + private List requestList(int eventCmd) { return requestLists[eventCmd]; } } +