[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 class DefaultArtifact
{
StringBuilder sb = new StringBuilder( 128 );
sb.append( getGroupId() );
sb.append( ":" );
sb.append( ':' );
appendArtifactTypeClassifierString( sb );
return sb.toString();
}
@ -238,11 +238,11 @@ public class DefaultArtifact
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 class DefaultArtifact
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 class DefaultArtifact
}
if ( scope != null )
{
sb.append( ":" );
sb.append( ':' );
sb.append( scope );
}
return sb.toString();

View File

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

View File

@ -175,7 +175,7 @@ public class AbstractArtifactResolutionException
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 @@ public class AbstractArtifactResolutionException
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 @@ public class AbstractArtifactResolutionException
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 class MultipleArtifactsNotFoundException
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 class DefaultArtifactVersion
{
comparable = new ComparableVersion( version );
int index = version.indexOf( "-" );
int index = version.indexOf( '-' );
String part1;
String part2 = null;

View File

@ -178,17 +178,17 @@ public class Restriction
{
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 class VersionRange
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 @@ public class VersionRange
Restriction restriction;
int index = process.indexOf( "," );
int index = process.indexOf( ',' );
if ( index < 0 )
{

View File

@ -151,7 +151,7 @@ class DefaultProblem
{
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 class DefaultArtifactRepository
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 class ManagedVersionMap
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 class ModelValidationResult
//
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 @@ public class MetadataResolutionResult
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 class MetadataGraph
}
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 class MetadataGraph
{
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 class MetadataGraphVertex
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 class LegacyLocalRepositoryManager
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 @@ public abstract class AbstractProjectInheritanceTestCase
{
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 class MavenArtifactRepository
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 class MavenArtifactRepository
*/
private static String protocol( final String url )
{
final int pos = url.indexOf( ":" );
final int pos = url.indexOf( ':' );
if ( pos == -1 )
{
@ -257,7 +257,7 @@ public class MavenArtifactRepository
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 abstract class AbstractRepositoryMetadata
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 class ArtifactResolutionResult
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 class LifecyclePhase
}
else
{
sb.append( "," );
sb.append( ',' );
}
sb.append( mojo.getGoal() );
}

View File

@ -175,7 +175,7 @@ public class MojoExecution
{
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 @@ public class PluginParameterException
if ( StringUtils.isEmpty( expression ) )
{
messageBuffer.append( "." );
messageBuffer.append( '.' );
}
else
{
@ -172,7 +172,7 @@ public class PluginParameterException
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 class PluginParameterException
decomposeParameterIntoUserInstructions( mojo, param, messageBuffer );
messageBuffer.append( "\n" );
messageBuffer.append( '\n' );
}
return messageBuffer.toString();

View File

@ -160,7 +160,7 @@ public class PluginParameterExpressionEvaluator
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 @@ public class PluginParameterExpressionEvaluator
{
try
{
int pathSeparator = expression.indexOf( "/" );
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
@ -253,7 +253,7 @@ public class PluginParameterExpressionEvaluator
{
try
{
int pathSeparator = expression.indexOf( "/" );
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
@ -285,7 +285,7 @@ public class PluginParameterExpressionEvaluator
{
try
{
int pathSeparator = expression.indexOf( "/" );
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
@ -313,7 +313,7 @@ public class PluginParameterExpressionEvaluator
{
try
{
int pathSeparator = expression.indexOf( "/" );
int pathSeparator = expression.indexOf( '/' );
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
@ -342,7 +342,7 @@ public class PluginParameterExpressionEvaluator
{
try
{
int pathSeparator = expression.indexOf( "/" );
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
@ -368,7 +368,7 @@ public class PluginParameterExpressionEvaluator
}
else if ( expression.startsWith( "basedir" ) )
{
int pathSeparator = expression.indexOf( "/" );
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
@ -447,7 +447,7 @@ public class PluginParameterExpressionEvaluator
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 class DefaultProjectDependenciesResolver
{
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 class DefaultProjectDependenciesResolver
{
buffer.append( " (version managed from " ).append( premanagedVersion );
appendManagementSource( buffer, art, "version" );
buffer.append( ")" );
buffer.append( ')' );
}
}
else

View File

@ -1133,9 +1133,9 @@ public class MavenProject
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 class ArtifactTransferEvent
public String toString()
{
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder( 64 );
sb.append( "TransferEvent[" );
@ -259,7 +259,7 @@ public class ArtifactTransferEvent
break;
}
sb.append( "|" );
sb.append( '|' );
switch ( this.getEventType() )
{
case TRANSFER_COMPLETED:
@ -282,9 +282,9 @@ public class ArtifactTransferEvent
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 abstract class AbstractArtifactMetadata
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 class LegacyLocalRepositoryManager
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 final class CLIReportingUtils
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 @@ public class MavenCli
String value;
int i = property.indexOf( "=" );
int i = property.indexOf( '=' );
if ( i <= 0 )
{

View File

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

View File

@ -59,7 +59,7 @@ public class UnsupportedSlf4jBindingConfiguration
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 class CLIManagerDocumentationTest
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 @@ public class DefaultModelBuilder
{
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 @@ public class DefaultModelBuilder
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 @@ public class DefaultModelBuilder
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 class DefaultModelProblem
{
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 @@ public class ModelProblemUtils
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 @@ public class MojoNotFoundException
{
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 class DefaultSettingsProblem
{
StringBuilder buffer = new StringBuilder( 128 );
buffer.append( "[" ).append( getSeverity() ).append( "] " );
buffer.append( '[' ).append( getSeverity() ).append( "] " );
buffer.append( getMessage() );
buffer.append( " @ " ).append( getLocation() );