From 735b72fcf1b848ee424d6755e5a624fbcbc65862 Mon Sep 17 00:00:00 2001 From: Artem Krosheninnikov Date: Thu, 9 Jan 2020 11:12:22 +0300 Subject: [PATCH] [MNG-6844] Use StandardCharsets and remove outdated @SuppressWarnings This closes #312 --- .../org/apache/maven/settings/GlobalSettingsTest.java | 3 ++- .../java/org/apache/maven/building/StringSource.java | 3 ++- .../inheritance/DefaultModelInheritanceAssembler.java | 3 --- .../artifact/AbstractArtifactComponentTestCase.java | 3 ++- .../apache/maven/repository/legacy/StringWagon.java | 10 ++-------- .../maven/artifact/handler/ArtifactHandlerTest.java | 1 - .../internal/stub/DefaultLifecyclesStub.java | 1 - .../maven/project/ExtensionDescriptorBuilderTest.java | 11 ++--------- .../main/java/org/apache/maven/cli/CLIManager.java | 2 +- .../interpolation/ProblemDetectingValueSource.java | 1 - 10 files changed, 11 insertions(+), 27 deletions(-) diff --git a/apache-maven/src/test/java/org/apache/maven/settings/GlobalSettingsTest.java b/apache-maven/src/test/java/org/apache/maven/settings/GlobalSettingsTest.java index 0d0543e289..257350c905 100644 --- a/apache-maven/src/test/java/org/apache/maven/settings/GlobalSettingsTest.java +++ b/apache-maven/src/test/java/org/apache/maven/settings/GlobalSettingsTest.java @@ -26,6 +26,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.nio.charset.StandardCharsets; /** * Tests that the global settings.xml shipped with the distribution is in good state. @@ -44,7 +45,7 @@ public class GlobalSettingsTest File globalSettingsFile = new File( basedir, "src/conf/settings.xml" ); assertTrue( globalSettingsFile.getAbsolutePath(), globalSettingsFile.isFile() ); - try ( Reader reader = new InputStreamReader( new FileInputStream( globalSettingsFile ), "UTF-8" ) ) + try ( Reader reader = new InputStreamReader( new FileInputStream( globalSettingsFile ), StandardCharsets.UTF_8) ) { new SettingsXpp3Reader().read( reader ); } diff --git a/maven-builder-support/src/main/java/org/apache/maven/building/StringSource.java b/maven-builder-support/src/main/java/org/apache/maven/building/StringSource.java index f9d87c0ba6..7705804aa4 100644 --- a/maven-builder-support/src/main/java/org/apache/maven/building/StringSource.java +++ b/maven-builder-support/src/main/java/org/apache/maven/building/StringSource.java @@ -22,6 +22,7 @@ package org.apache.maven.building; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; /** * Wraps an ordinary {@link CharSequence} as a source. @@ -62,7 +63,7 @@ public class StringSource public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream( content.getBytes( "UTF-8" ) ); + return new ByteArrayInputStream( content.getBytes( StandardCharsets.UTF_8 ) ); } @Override diff --git a/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java b/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java index 81ea92d99a..b0bbe66ba8 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java +++ b/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java @@ -55,7 +55,6 @@ public class DefaultModelInheritanceAssembler implements ModelInheritanceAssembler { // TODO Remove this! - @SuppressWarnings( "unchecked" ) public void assembleBuildInheritance( Build childBuild, Build parentBuild, boolean handleAsInheritance ) { // The build has been set but we want to step in here and fill in @@ -307,7 +306,6 @@ public class DefaultModelInheritanceAssembler } // TODO Remove this! - @SuppressWarnings( "unchecked" ) private void assembleDependencyManagementInheritance( Model child, Model parent ) { DependencyManagement parentDepMgmt = parent.getDependencyManagement(); @@ -527,7 +525,6 @@ public class DefaultModelInheritanceAssembler } // TODO Remove this! - @SuppressWarnings( "unchecked" ) private void assembleDependencyInheritance( Model child, Model parent ) { Map depsMap = new LinkedHashMap<>(); diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java index 2ce3794079..dbd6e8ffd7 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java @@ -59,6 +59,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -293,7 +294,7 @@ public abstract class AbstractArtifactComponentTestCase { artifactFile.getParentFile().mkdirs(); } - try ( Writer writer = new OutputStreamWriter( new FileOutputStream( artifactFile ), "ISO-8859-1" ) ) + try ( Writer writer = new OutputStreamWriter( new FileOutputStream( artifactFile ), StandardCharsets.ISO_8859_1) ) { writer.write( artifact.getId() ); } diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/StringWagon.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/StringWagon.java index 944cce62d7..3a72b98e9a 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/StringWagon.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/StringWagon.java @@ -22,6 +22,7 @@ package org.apache.maven.repository.legacy; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -72,14 +73,7 @@ public class StringWagon resource.setContentLength( content.length() ); resource.setLastModified( System.currentTimeMillis() ); - try - { - inputData.setInputStream( new ByteArrayInputStream( content.getBytes( "UTF-8" ) ) ); - } - catch ( UnsupportedEncodingException e ) - { - throw new Error( "broken JVM", e ); - } + inputData.setInputStream( new ByteArrayInputStream( content.getBytes( StandardCharsets.UTF_8 ) ) ); } else { diff --git a/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java index 69f59fdb36..2803d8d80a 100644 --- a/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java +++ b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java @@ -33,7 +33,6 @@ public class ArtifactHandlerTest { File apt = getTestFile( "src/site/apt/artifact-handlers.apt" ); - @SuppressWarnings( "unchecked" ) List lines = FileUtils.loadFile( apt ); for ( String line : lines ) diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java index 1dc2b6b0a6..a1a9532294 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java @@ -47,7 +47,6 @@ public class DefaultLifecyclesStub List stubSiteCycle = Arrays.asList( PRE_SITE.getPhase(), SITE.getPhase(), POST_SITE.getPhase(), SITE_DEPLOY.getPhase() ); - @SuppressWarnings( "unchecked" ) Iterator> lcs = Arrays.asList( stubDefaultCycle, stubCleanCycle, stubSiteCycle ).iterator(); Map lifeCycles = new HashMap<>(); diff --git a/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java index 7a5e55d1eb..5ac8f611cf 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java @@ -25,7 +25,7 @@ import static org.junit.Assert.assertThat; import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import junit.framework.TestCase; @@ -61,14 +61,7 @@ public class ExtensionDescriptorBuilderTest private InputStream toStream( String xml ) { - try - { - return new ByteArrayInputStream( xml.getBytes( "UTF-8" ) ); - } - catch ( UnsupportedEncodingException e ) - { - throw new IllegalStateException( e ); - } + return new ByteArrayInputStream( xml.getBytes( StandardCharsets.UTF_8 ) ); } public void testEmptyDescriptor() diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java index ec5e1b11c0..c9e002a10e 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java @@ -107,7 +107,7 @@ public class CLIManager protected Options options; - @SuppressWarnings( { "static-access", "checkstyle:linelength" } ) + @SuppressWarnings( "checkstyle:linelength" ) public CLIManager() { options = new Options(); diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/ProblemDetectingValueSource.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/ProblemDetectingValueSource.java index 4ed98d035d..0b29f20e71 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/ProblemDetectingValueSource.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/ProblemDetectingValueSource.java @@ -72,7 +72,6 @@ class ProblemDetectingValueSource } @Override - @SuppressWarnings( "unchecked" ) public List getFeedback() { return valueSource.getFeedback();