You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2019/05/08 20:06:37 UTC

More Vector -> ArrayList

-----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?

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlzTNswACgkQHPApP6U8
pFgHNw//cNV2tvwaSwkDh+dLQZSJrU29nscuKMPrX9LWw9d0LVMHKgBxZ6aeFxeN
cpzEYKZ48u5h0NfCyiswehiG7aowbAxDT2/Q16HOp1L46sPhnQv5XECDn1HthqnK
9Zj+CKaDeirohOev6E7Vnl9sHZ4khAIRjLpZzaGb8OStE5A+z8U3LNz3qnGA90uy
RckCyPG4Azcf614xn1biaPlc6ahSeLmPeu2jxIItZPETBXdDiBQo9VpkzYR5grD6
lDWb2dNO1Yxz57rNmWE7ohEt2pWq+G4knrNMihOVkNFPzOh1cPf4RgWLddGtJWlu
d5Ob/t2NH10fgWNtPomPojriUK/wnXIj/3CsU67EKNVgzAEWQ8RB8uh1IP22aemw
cRKCEUI6RvDToxA+eFcbRcUlxYA7Tvfj8L0JcMt8dqbWwzFYeZ41bj1jZ/jXi139
sUgKMajuPZZ7Y0/ThVwivSKBZzjLLjgjHha8xctbHTkl1VcK+Ul0O2qb3r9nXwuO
O/16OKGnUw8p3DgUi3f0fh7jOoovXMJH/dvNf7vv6OjOWUopq4vfp0Su8Oay9+09
vIk45Gnl6LGYSW4hn4mv5T64Wwyg7g7+LxS0INCrESohNeEkQWAyrd43r9bkxPZQ
5BwXn8pVJfiLDGXXSMFZ25Q2yXSm2fY4t7BJIsbz7N56XqlXNOo=
=qpWc
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: More Vector -> ArrayList

Posted by Rémy Maucherat <re...@apache.org>.
On Wed, May 8, 2019 at 10:06 PM Christopher Schultz <
chris@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