commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Feist (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (COLLECTIONS-519) private constructors in utility classes break existing code
Date Thu, 01 May 2014 10:32:15 GMT

    [ https://issues.apache.org/jira/browse/COLLECTIONS-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13986484#comment-13986484
] 

Daniel Feist edited comment on COLLECTIONS-519 at 5/1/14 10:30 AM:
-------------------------------------------------------------------

This is a major issue for us with Mule use of commons-collections too as we plan to upgrade
from to version 4 with generics :-(

We extend commons collections utility clases and add a few extras with the goal that everywhere
in our code base we just use a single utility class that provides all commons-collections
methods plus our own.  See: https://raw.githubusercontent.com/mulesoft/mule/477feb5e0c5df246865501eb995cf0b2e7e07bc2/core/src/main/java/org/mule/util/MapUtils.java

While i agree the *constructor shouldn't be public*, it *should at least be protected though
to allow extension*, else you may as well make the class final because the effect is the same.
 To goal of this change was (based on the javadoc) to prevent instantiation, not to prevent
extension.


was (Author: dfeist):
This is a major issue for us with Mule use of commons-collections too as we plan to upgrade
from to version 4 with generics :-(

We extends commons collections utility clases and add a few extras with the goal that everywhere
in our code base we just use a single utility class that provides all commons-collections
methods plus our own.

While i agree the *constructor shouldn't be public*, it *should at least be protected though
to allow extension*, else you may as well make the class final because the effect is the same.
 To goal of this change was (based on the javadoc) to prevent instantiation, not to prevent
extension.

> private constructors in utility classes break existing code
> -----------------------------------------------------------
>
>                 Key: COLLECTIONS-519
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-519
>             Project: Commons Collections
>          Issue Type: Bug
>    Affects Versions: 4.x
>            Reporter: Radoslav Paskalev
>
> Hello,
> In collections version 4.x all utility classes (example ListUtils, MapUtils, PredicateUtils....)
have private constructors. I consider this to be a serious bug, as it breaks any possibility
the classes to be extended by the users.  The javadoc says that constructors are private in
order to prevent class instantiation but this object instantiation is not really problem and
i think it is more important to allow classes to be extended. The possibility to extend utility
classes was one of the major selling points of commons.lang and commons.collections projects.
In the latest commons.lang project the utility classes still have public constructors.
> Best Regards



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message