You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Guillaume Boué (JIRA)" <ji...@apache.org> on 2017/06/09 23:21:18 UTC

[jira] [Commented] (MANTRUN-204) antrun loops the backing map of java.util.Properties withouth checking type safety

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

Guillaume Boué commented on MANTRUN-204:
----------------------------------------

Putting a Boolean value into a Properties object is a misuse of the API. That part of the code was already changed in [r1797111|http://svn.apache.org/r1797111] to rely on {{stringPropertyNames()}}, and there are no blind casts anymore.

There is still {{copyProperties( Project antProject, MavenProject mavenProject )}} which could be improved, by not casting to String but calling {{toString()}} instead on the Ant property value. Ant's {{Project.getProperties()}} returns a {{Hashtable&#60;String,Object&#62;}} that cannot contain {{null}} for both keys and values, so there is no need to check for this.

> antrun loops the backing map of java.util.Properties withouth checking type safety
> ----------------------------------------------------------------------------------
>
>                 Key: MANTRUN-204
>                 URL: https://issues.apache.org/jira/browse/MANTRUN-204
>             Project: Maven Antrun Plugin
>          Issue Type: Bug
>    Affects Versions: 1.8
>         Environment: seen in maven 3.3.3, maven 3.3.9
>            Reporter: Gene Smith
>
> In AntRunMojo's copyProperties method, visible at either of these:
>     http://svn.apache.org/viewvc/maven/plugins/tags/maven-antrun-plugin-1.8/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java?view=markup#l401
>     http://grepcode.com/file/repo1.maven.org/maven2/org.apache.maven.plugins/maven-antrun-plugin/1.8/org/apache/maven/plugin/antrun/AntRunMojo.java#AntRunMojo
> This loop does not check the type of objects in the Properties object it is looping:
>  	        Properties mavenProps = mavenProject.getProperties();
>  	        for ( Map.Entry<?, ?> entry : mavenProps.entrySet() )
>  	        {
>  	            antProject.setProperty( (String) entry.getKey(), (String) entry.getValue() );
>  	        }
> Antrun 1.7 used an iterator and java.util.Properties' getters and setters (so the conversion was done for it).
> The Properties object itself allows access to the backing map but strongly discourages using it.  For type safety, if you loop the entryset you need to check types (or check null and call "toString" instead of casting).  Maven does NOT enforce the type of objects put into that map, so
> some plugins put non String objects in it.  (In my use case, "org.eclipse.rcptt:rcptt-maven-plugin" stores a boolean in it.)
> ....
> As a work around I antrun 1.7 in this usecase.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)