[MNG-5934] String handling issues identified by PMD

This commit is contained in:
Alex Henrie 2016-01-19 20:04:59 +01:00 committed by Michael Osipov
parent 0514c1b14e
commit 8d91726f78
38 changed files with 98 additions and 99 deletions

View File

@ -230,7 +230,7 @@ public String getDependencyConflictId()
{
StringBuilder sb = new StringBuilder( 128 );
sb.append( getGroupId() );
sb.append( ":" );
sb.append( ':' );
appendArtifactTypeClassifierString( sb );
return sb.toString();
}
@ -238,11 +238,11 @@ public String getDependencyConflictId()
private void appendArtifactTypeClassifierString( StringBuilder sb )
{
sb.append( getArtifactId() );
sb.append( ":" );
sb.append( ':' );
sb.append( getType() );
if ( hasClassifier() )
{
sb.append( ":" );
sb.append( ':' );
sb.append( getClassifier() );
}
}
@ -285,10 +285,10 @@ public String toString()
if ( getGroupId() != null )
{
sb.append( getGroupId() );
sb.append( ":" );
sb.append( ':' );
}
appendArtifactTypeClassifierString( sb );
sb.append( ":" );
sb.append( ':' );
if ( getBaseVersionInternal() != null )
{
sb.append( getBaseVersionInternal() );
@ -299,7 +299,7 @@ public String toString()
}
if ( scope != null )
{
sb.append( ":" );
sb.append( ':' );
sb.append( scope );
}
return sb.toString();

View File

@ -160,7 +160,7 @@ public String toString()
buffer.append( checksumPolicy );
buffer.append( ", updates=" );
buffer.append( updatePolicy );
buffer.append( "}" );
buffer.append( '}' );
return buffer.toString();
}

View File

@ -175,7 +175,7 @@ protected static String constructArtifactPath( List<String> path,
for ( Iterator<String> i = path.iterator(); i.hasNext(); num++ )
{
sb.append( indentation );
sb.append( "\t" );
sb.append( '\t' );
sb.append( num );
sb.append( ") " );
sb.append( i.next() );
@ -201,8 +201,8 @@ private static String constructMessageBase( String message,
if ( message == null || !message.contains( "from the specified remote repositories:" ) )
{
sb.append( LS );
sb.append( " " ).append( groupId ).append( ":" ).append( artifactId ).append( ":" ).append( type ).append(
":" ).append( version );
sb.append( " " ).append( groupId ).append( ':' ).append( artifactId ).append( ':' ).append( type ).append(
':' ).append( version );
sb.append( LS );
if ( remoteRepositories != null )
{
@ -235,10 +235,10 @@ private static String constructMessageBase( String message,
sb.append( ", snapshots=" ).append( snapshots.isEnabled() );
}
sb.append( ")" );
sb.append( ')' );
if ( i.hasNext() )
{
sb.append( "," ).append( LS ).append( " " );
sb.append( ',' ).append( LS ).append( " " );
}
}
}

View File

@ -84,8 +84,9 @@ public List<Artifact> getMissingArtifacts()
private static String constructMessage( List<Artifact> artifacts )
{
StringBuilder buffer = new StringBuilder( "Missing:\n" );
StringBuilder buffer = new StringBuilder( 256 );
buffer.append( "Missing:\n" );
buffer.append( "----------\n" );
int counter = 0;

View File

@ -111,7 +111,7 @@ public final void parseVersion( String version )
{
comparable = new ComparableVersion( version );
int index = version.indexOf( "-" );
int index = version.indexOf( '-' );
String part1;
String part2 = null;

View File

@ -178,17 +178,17 @@ public String toString()
{
StringBuilder buf = new StringBuilder();
buf.append( isLowerBoundInclusive() ? "[" : "(" );
buf.append( isLowerBoundInclusive() ? '[' : '(' );
if ( getLowerBound() != null )
{
buf.append( getLowerBound().toString() );
}
buf.append( "," );
buf.append( ',' );
if ( getUpperBound() != null )
{
buf.append( getUpperBound().toString() );
}
buf.append( isUpperBoundInclusive() ? "]" : ")" );
buf.append( isUpperBoundInclusive() ? ']' : ')' );
return buf.toString();
}

View File

@ -104,8 +104,8 @@ public static VersionRange createFromVersionSpec( String spec )
while ( process.startsWith( "[" ) || process.startsWith( "(" ) )
{
int index1 = process.indexOf( ")" );
int index2 = process.indexOf( "]" );
int index1 = process.indexOf( ')' );
int index2 = process.indexOf( ']' );
int index = index2;
if ( index2 < 0 || index1 < index2 )
@ -171,7 +171,7 @@ private static Restriction parseRestriction( String spec )
Restriction restriction;
int index = process.indexOf( "," );
int index = process.indexOf( ',' );
if ( index < 0 )
{

View File

@ -151,7 +151,7 @@ public String toString()
{
StringBuilder buffer = new StringBuilder( 128 );
buffer.append( "[" ).append( getSeverity() ).append( "] " );
buffer.append( '[' ).append( getSeverity() ).append( "] " );
buffer.append( getMessage() );
buffer.append( " @ " ).append( getLocation() );

View File

@ -175,11 +175,11 @@ public void setBlacklisted( boolean blacklisted )
public String toString()
{
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder( 256 );
sb.append( " id: " ).append( getId() ).append( "\n" );
sb.append( " url: " ).append( getUrl() ).append( "\n" );
sb.append( " layout: " ).append( layout != null ? layout : "none" ).append( "\n" );
sb.append( " id: " ).append( getId() ).append( '\n' );
sb.append( " url: " ).append( getUrl() ).append( '\n' );
sb.append( " layout: " ).append( layout != null ? layout : "none" ).append( '\n' );
if ( snapshots != null )
{

View File

@ -45,10 +45,10 @@ public String toString()
while ( iter.hasNext() )
{
String key = iter.next();
buffer.append( key ).append( "=" ).append( get( key ) );
buffer.append( key ).append( '=' ).append( get( key ) );
if ( iter.hasNext() )
{
buffer.append( "\n" );
buffer.append( '\n' );
}
}
return buffer.toString();

View File

@ -85,7 +85,7 @@ public String render( String indentation )
//
for ( int i = 0; i < messages.size(); i++ )
{
message.append( indentation ).append( "[" ).append( i ).append( "] " ).append( messages.get( i ) ).append(
message.append( indentation ).append( '[' ).append( i ).append( "] " ).append( messages.get( i ) ).append(
NEWLINE );
}

View File

@ -322,21 +322,19 @@ private <T> List<T> initList( final List<T> l )
public String toString()
{
StringBuilder sb = new StringBuilder();
if ( artifacts == null )
return "";
if ( artifacts != null )
StringBuilder sb = new StringBuilder( 256 );
int i = 1;
sb.append( "---------\n" );
sb.append( artifacts.size() ).append( '\n' );
for ( Artifact a : artifacts )
{
int i = 1;
sb.append( "---------" ).append( "\n" );
sb.append( artifacts.size() ).append( "\n" );
for ( Artifact a : artifacts )
{
sb.append( i ).append( " " ).append( a ).append( "\n" );
i++;
}
sb.append( "---------" ).append( "\n" );
sb.append( i ).append( ' ' ).append( a ).append( '\n' );
i++;
}
sb.append( "---------\n" );
return sb.toString();
}

View File

@ -486,13 +486,13 @@ public String toString()
}
for ( MetadataGraphVertex v : vertices )
{
sb.append( "Vertex: " ).append( v.getMd().toString() ).append( "\n" );
sb.append( "Vertex: " ).append( v.getMd().toString() ).append( '\n' );
List<MetadataGraphEdge> ins = getIncidentEdges( v );
if ( ins != null )
{
for ( MetadataGraphEdge e : ins )
{
sb.append( " from : " ).append( e.toString() ).append( "\n" );
sb.append( " from : " ).append( e.toString() ).append( '\n' );
}
}
else
@ -505,7 +505,7 @@ public String toString()
{
for ( MetadataGraphEdge e : outs )
{
sb.append( " to : " ).append( e.toString() ).append( "\n" );
sb.append( " to : " ).append( e.toString() ).append( '\n' );
}
}
else

View File

@ -192,17 +192,17 @@ public int hashCode()
return super.hashCode();
}
StringBuilder hashString = new StringBuilder( 128 );
hashString.append( md.groupId ).append( "|" );
hashString.append( md.artifactId ).append( "|" );
hashString.append( md.groupId ).append( '|' );
hashString.append( md.artifactId ).append( '|' );
if ( compareVersion )
{
hashString.append( md.version ).append( "|" );
hashString.append( md.version ).append( '|' );
}
if ( compareScope )
{
hashString.append( md.getArtifactScope() ).append( "|" );
hashString.append( md.getArtifactScope() ).append( '|' );
}
return hashString.toString().hashCode();

View File

@ -59,7 +59,7 @@ public String getPathForLocalArtifact( Artifact artifact )
path.append( artifact.getGroupId() ).append( '/' );
path.append( artifact.getExtension() ).append( 's' ).append( '/' );
path.append( artifact.getExtension() ).append( "s/" );
path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() );

View File

@ -33,7 +33,7 @@ protected String getTestSeries()
{
String className = getClass().getPackage().getName();
return className.substring( className.lastIndexOf( "." ) + 1 );
return className.substring( className.lastIndexOf( '.' ) + 1 );
}
protected File projectFile( String name )

View File

@ -132,15 +132,15 @@ public String getKey()
public String toString()
{
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder( 256 );
sb.append( " id: " ).append( getId() ).append( "\n" );
sb.append( " url: " ).append( getUrl() ).append( "\n" );
sb.append( " layout: " ).append( layout != null ? layout : "none" ).append( "\n" );
sb.append( " id: " ).append( getId() ).append( '\n' );
sb.append( " url: " ).append( getUrl() ).append( '\n' );
sb.append( " layout: " ).append( layout != null ? layout : "none" ).append( '\n' );
if ( proxy != null )
{
sb.append( " proxy: " ).append( proxy.getHost() ).append( ":" ).append( proxy.getPort() ).append( "\n" );
sb.append( " proxy: " ).append( proxy.getHost() ).append( ':' ).append( proxy.getPort() ).append( '\n' );
}
if ( snapshots != null )
@ -220,7 +220,7 @@ public void setUrl( String url )
*/
private static String protocol( final String url )
{
final int pos = url.indexOf( ":" );
final int pos = url.indexOf( ':' );
if ( pos == -1 )
{
@ -257,7 +257,7 @@ private String basedir( String url )
else
{
// Now we expect the host
int index = retValue.indexOf( "/" );
int index = retValue.indexOf( '/' );
if ( index >= 0 )
{
retValue = retValue.substring( index + 1 );

View File

@ -197,7 +197,7 @@ public void merge( ArtifactMetadata metadata )
public String extendedToString()
{
StringBuilder buffer = new StringBuilder();
StringBuilder buffer = new StringBuilder( 256 );
buffer.append( "\nRepository Metadata\n--------------------------" );
buffer.append( "\nGroupId: " ).append( getGroupId() );

View File

@ -343,14 +343,14 @@ public String toString()
if ( artifacts != null )
{
int i = 1;
sb.append( "---------" ).append( "\n" );
sb.append( artifacts.size() ).append( "\n" );
sb.append( "---------\n" );
sb.append( artifacts.size() ).append( '\n' );
for ( Artifact a : artifacts )
{
sb.append( i ).append( " " ).append( a ).append( "\n" );
sb.append( i ).append( ' ' ).append( a ).append( '\n' );
i++;
}
sb.append( "---------" ).append( "\n" );
sb.append( "---------\n" );
}
return sb.toString();

View File

@ -84,7 +84,7 @@ public String toString()
}
else
{
sb.append( "," );
sb.append( ',' );
}
sb.append( mojo.getGoal() );
}

View File

@ -175,7 +175,7 @@ public String toString()
{
buffer.append( mojoDescriptor.getId() );
}
buffer.append( " {execution: " ).append( executionId ).append( "}" );
buffer.append( " {execution: " ).append( executionId ).append( '}' );
return buffer.toString();
}

View File

@ -151,7 +151,7 @@ else if ( isMap )
if ( StringUtils.isEmpty( expression ) )
{
messageBuffer.append( "." );
messageBuffer.append( '.' );
}
else
{
@ -172,7 +172,7 @@ public String buildDiagnosticMessage()
MojoDescriptor mojo = getMojoDescriptor();
messageBuffer.append( "One or more required plugin parameters are invalid/missing for \'" )
.append( mojo.getPluginDescriptor().getGoalPrefix() ).append( ":" ).append( mojo.getGoal() )
.append( mojo.getPluginDescriptor().getGoalPrefix() ).append( ':' ).append( mojo.getGoal() )
.append( "\'\n" );
int idx = 0;
@ -184,7 +184,7 @@ public String buildDiagnosticMessage()
decomposeParameterIntoUserInstructions( mojo, param, messageBuffer );
messageBuffer.append( "\n" );
messageBuffer.append( '\n' );
}
return messageBuffer.toString();

View File

@ -160,7 +160,7 @@ public Object evaluate( String expr, Class<?> type )
int index = expr.indexOf( "${" );
if ( index >= 0 )
{
int lastIndex = expr.indexOf( "}", index );
int lastIndex = expr.indexOf( '}', index );
if ( lastIndex >= 0 )
{
String retVal = expr.substring( 0, index );
@ -213,7 +213,7 @@ else if ( expression.startsWith( "session" ) )
{
try
{
int pathSeparator = expression.indexOf( "/" );
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
@ -253,7 +253,7 @@ else if ( expression.startsWith( "project" ) || expression.startsWith( "pom" ) )
{
try
{
int pathSeparator = expression.indexOf( "/" );
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
@ -285,7 +285,7 @@ else if ( expression.startsWith( "mojo" ) )
{
try
{
int pathSeparator = expression.indexOf( "/" );
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
@ -313,7 +313,7 @@ else if ( expression.startsWith( "plugin" ) )
{
try
{
int pathSeparator = expression.indexOf( "/" );
int pathSeparator = expression.indexOf( '/' );
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
@ -342,7 +342,7 @@ else if ( expression.startsWith( "settings" ) )
{
try
{
int pathSeparator = expression.indexOf( "/" );
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
@ -368,7 +368,7 @@ else if ( "basedir".equals( expression ) )
}
else if ( expression.startsWith( "basedir" ) )
{
int pathSeparator = expression.indexOf( "/" );
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
@ -447,7 +447,7 @@ private static boolean isTypeCompatible( Class<?> type, Object value )
private String stripTokens( String expr )
{
if ( expr.startsWith( "${" ) && ( expr.indexOf( "}" ) == expr.length() - 1 ) )
if ( expr.startsWith( "${" ) && ( expr.indexOf( '}' ) == expr.length() - 1 ) )
{
expr = expr.substring( 2, expr.length() - 1 );
}

View File

@ -263,7 +263,7 @@ public boolean visitEnter( DependencyNode node )
{
buffer.append( " (scope managed from " ).append( premanagedScope );
appendManagementSource( buffer, art, "scope" );
buffer.append( ")" );
buffer.append( ')' );
}
String premanagedVersion = DependencyManagerUtils.getPremanagedVersion( node );
@ -271,7 +271,7 @@ public boolean visitEnter( DependencyNode node )
{
buffer.append( " (version managed from " ).append( premanagedVersion );
appendManagementSource( buffer, art, "version" );
buffer.append( ")" );
buffer.append( ')' );
}
}
else

View File

@ -1133,9 +1133,9 @@ public String toString()
StringBuilder sb = new StringBuilder( 128 );
sb.append( "MavenProject: " );
sb.append( getGroupId() );
sb.append( ":" );
sb.append( ':' );
sb.append( getArtifactId() );
sb.append( ":" );
sb.append( ':' );
sb.append( getVersion() );
sb.append( " @ " );

View File

@ -242,7 +242,7 @@ public void setDataLength( int dataLength )
public String toString()
{
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder( 64 );
sb.append( "TransferEvent[" );
@ -259,7 +259,7 @@ public String toString()
break;
}
sb.append( "|" );
sb.append( '|' );
switch ( this.getEventType() )
{
case TRANSFER_COMPLETED:
@ -282,9 +282,9 @@ public String toString()
break;
}
sb.append( "|" );
sb.append( this.getLocalFile() ).append( "|" );
sb.append( "]" );
sb.append( '|' );
sb.append( this.getLocalFile() ).append( '|' );
sb.append( ']' );
return sb.toString();
}

View File

@ -53,7 +53,7 @@ public String getArtifactId()
public String extendedToString()
{
StringBuilder buffer = new StringBuilder();
StringBuilder buffer = new StringBuilder( 256 );
buffer.append( "\nArtifact Metadata\n--------------------------" );
buffer.append( "\nGroupId: " ).append( getGroupId() );

View File

@ -59,7 +59,7 @@ public String getPathForLocalArtifact( Artifact artifact )
path.append( artifact.getGroupId() ).append( '/' );
path.append( artifact.getExtension() ).append( 's' ).append( '/' );
path.append( artifact.getExtension() ).append( "s/" );
path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() );

View File

@ -71,7 +71,7 @@ public static String showVersion()
version.append( "Default locale: " ).append( Locale.getDefault() ).append( ", platform encoding: " ).append(
System.getProperty( "file.encoding", "<unknown encoding>" ) ).append( ls );
version.append( "OS name: \"" ).append( Os.OS_NAME ).append( "\", version: \"" ).append( Os.OS_VERSION ).append(
"\", arch: \"" ).append( Os.OS_ARCH ).append( "\", family: \"" ).append( Os.OS_FAMILY ).append( "\"" );
"\", arch: \"" ).append( Os.OS_ARCH ).append( "\", family: \"" ).append( Os.OS_FAMILY ).append( '\"' );
return version.toString();
}

View File

@ -1621,7 +1621,7 @@ private static void setCliProperty( String property, Properties properties )
String value;
int i = property.indexOf( "=" );
int i = property.indexOf( '=' );
if ( i <= 0 )
{

View File

@ -174,7 +174,7 @@ else if ( buildSummary instanceof BuildSuccess )
buffer.append( chars( ' ', padSize ) );
}
buffer.append( buildTimeDuration );
buffer.append( "]" );
buffer.append( ']' );
}
else if ( buildSummary instanceof BuildFailure )
{
@ -187,7 +187,7 @@ else if ( buildSummary instanceof BuildFailure )
buffer.append( chars( ' ', padSize ) );
}
buffer.append( buildTimeDuration );
buffer.append( "]" );
buffer.append( ']' );
}
logger.info( buffer.toString() );

View File

@ -59,7 +59,7 @@ public void activate()
for ( Map.Entry<URL, Set<Object>> entry : supported.entrySet() )
{
StringBuilder sb = new StringBuilder();
sb.append( "(from " ).append( entry.getKey().toExternalForm() ).append( ")" );
sb.append( "(from " ).append( entry.getKey().toExternalForm() ).append( ')' );
for ( Object binding : entry.getValue() )
{

View File

@ -62,7 +62,7 @@ public Collection<Option> getOptions()
public String getOptionsAsHtml()
{
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder( 512 );
boolean a = true;
sb.append( "<table border='1' class='zebra-striped'><tr class='a'><th><b>Options</b></th><th><b>Description</b></th></tr>" );
for ( Option option : new CLIManagerExtension().getOptions() )

View File

@ -914,8 +914,8 @@ private ModelData readParentLocally( Model childModel, ModelSource childSource,
{
buffer.append( " of POM " ).append( ModelProblemUtils.toSourceHint( childModel ) );
}
buffer.append( " points at " ).append( groupId ).append( ":" ).append( artifactId );
buffer.append( " instead of " ).append( parent.getGroupId() ).append( ":" );
buffer.append( " points at " ).append( groupId ).append( ':' ).append( artifactId );
buffer.append( " instead of " ).append( parent.getGroupId() ).append( ':' );
buffer.append( parent.getArtifactId() ).append( ", please verify your project structure" );
problems.setSource( childModel );
@ -1028,7 +1028,7 @@ private ModelData readParentExternally( Model childModel, ModelBuildingRequest r
buffer.append( "Non-resolvable parent POM" );
if ( !containsCoordinates( e.getMessage(), groupId, artifactId, version ) )
{
buffer.append( " " ).append( ModelProblemUtils.toId( groupId, artifactId, version ) );
buffer.append( ' ' ).append( ModelProblemUtils.toId( groupId, artifactId, version ) );
}
if ( childModel != problems.getRootModel() )
{
@ -1221,7 +1221,7 @@ private void importDependencyManagement( Model model, ModelBuildingRequest reque
buffer.append( "Non-resolvable import POM" );
if ( !containsCoordinates( e.getMessage(), groupId, artifactId, version ) )
{
buffer.append( " " ).append( ModelProblemUtils.toId( groupId, artifactId, version ) );
buffer.append( ' ' ).append( ModelProblemUtils.toId( groupId, artifactId, version ) );
}
buffer.append( ": " ).append( e.getMessage() );

View File

@ -165,7 +165,7 @@ public String toString()
{
StringBuilder buffer = new StringBuilder( 128 );
buffer.append( "[" ).append( getSeverity() ).append( "] " );
buffer.append( '[' ).append( getSeverity() ).append( "] " );
buffer.append( getMessage() );
buffer.append( " @ " ).append( ModelProblemUtils.formatLocation( this, null ) );

View File

@ -51,7 +51,7 @@ static String toSourceHint( Model model )
File pomFile = model.getPomFile();
if ( pomFile != null )
{
buffer.append( " (" ).append( pomFile ).append( ")" );
buffer.append( " (" ).append( pomFile ).append( ')' );
}
return buffer.toString();

View File

@ -54,7 +54,7 @@ private static String toMessage( String goal, PluginDescriptor pluginDescriptor
{
StringBuilder buffer = new StringBuilder( 256 );
buffer.append( "Could not find goal '" ).append( goal ).append( "'" );
buffer.append( "Could not find goal '" ).append( goal ).append( '\'' );
if ( pluginDescriptor != null )
{

View File

@ -156,7 +156,7 @@ public String toString()
{
StringBuilder buffer = new StringBuilder( 128 );
buffer.append( "[" ).append( getSeverity() ).append( "] " );
buffer.append( '[' ).append( getSeverity() ).append( "] " );
buffer.append( getMessage() );
buffer.append( " @ " ).append( getLocation() );