On Wed, May 8, 2019 at 10:06 PM Christopher Schultz < ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA256 > > All, > > It seems that Vector is used a lot in Tomcat code. > > Since the JSP engine is riddled with uses, I figured I'd start > elsewhere with my cleanup. Here's something glaring: > > o.a.c.connector.Response:882 > > @Override > public Collection<String> getHeaders(String name) { > > Enumeration<String> enumeration = > getCoyoteResponse().getMimeHeaders().values(name); > Vector<String> result = new Vector<>(); > while (enumeration.hasMoreElements()) { > result.addElement(enumeration.nextElement()); > } > return result; > } > > This one is straightforward to replace with ArrayList, but the > semantics will change because ArrayList is not synchronized. > > Shall I return Collections.synchronizedCollection(...) or is it okay > to change this from a synchronized list to an unsynchronized one? I > can't find any reference to a requirement that the return value from > this method is thread-safe, and, in general, classes such as > HttpServletResponse are not considered thread-safe, so neither should > the return values from any of their methods IMO. > > Any thoughts? > It uses a Vector because it was copied from older code (getHeaderValues) and that's it. There's no need for sync here. Rémy