Make fields final

Closes gh-33537
This commit is contained in:
Moritz Halbritter
2022-12-16 14:28:44 +01:00
parent 216d15997a
commit 725337f976
285 changed files with 445 additions and 437 deletions

View File

@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class JsonStreamTests extends AbstractJsonTests {
private JsonStream jsonStream;
private final JsonStream jsonStream;
JsonStreamTests() {
this.jsonStream = new JsonStream(getObjectMapper());

View File

@@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class FileDescriptorTests {
private int sourceHandle = 123;
private final int sourceHandle = 123;
private int closedHandle = 0;

View File

@@ -29,7 +29,7 @@ class SentenceExtractorTests {
private static final String NEW_LINE = System.lineSeparator();
private SentenceExtractor extractor = new SentenceExtractor();
private final SentenceExtractor extractor = new SentenceExtractor();
@Test
void extractFirstSentence() {

View File

@@ -113,7 +113,7 @@ public abstract class AbstractFieldValuesProcessorTests {
private FieldValuesParser processor;
private Map<String, Object> values = new HashMap<>();
private final Map<String, Object> values = new HashMap<>();
@Override
public synchronized void init(ProcessingEnvironment env) {

View File

@@ -35,9 +35,9 @@ import org.springframework.util.FileCopyUtils;
*/
class PomCondition extends Condition<File> {
private Set<String> expectedContents;
private final Set<String> expectedContents;
private Set<String> notExpectedContents;
private final Set<String> notExpectedContents;
PomCondition() {
this(new HashSet<>(), new HashSet<>());

View File

@@ -83,11 +83,11 @@ public class GradleBuild {
private GradleVersion expectDeprecationWarnings;
private List<String> expectedDeprecationMessages = new ArrayList<>();
private final List<String> expectedDeprecationMessages = new ArrayList<>();
private boolean configurationCache = false;
private Map<String, String> scriptProperties = new HashMap<>();
private final Map<String, String> scriptProperties = new HashMap<>();
public GradleBuild() {
this(Dsl.GROOVY);

View File

@@ -38,7 +38,7 @@ public class GradleBuildExtension implements BeforeEachCallback, AfterEachCallba
private static final Pattern GRADLE_VERSION_PATTERN = Pattern.compile("\\[Gradle .+\\]");
private Dsl dsl = Dsl.GROOVY;
private final Dsl dsl = Dsl.GROOVY;
@Override
public void beforeEach(ExtensionContext context) throws Exception {

View File

@@ -27,7 +27,7 @@ import java.util.Map;
*/
class ListCommand extends Command {
private Context context;
private final Context context;
ListCommand(Context context) {
super("list", "List layers from the jar that can be extracted", Options.none(), Parameters.none());

View File

@@ -75,7 +75,7 @@ class ExtractCommandTests {
private File extract;
private Layers layers = new TestLayers();
private final Layers layers = new TestLayers();
private ExtractCommand command;

View File

@@ -37,7 +37,7 @@ import org.springframework.util.FileCopyUtils;
*/
class TestPrintStream extends PrintStream implements AssertProvider<PrintStreamAssert> {
private Class<? extends Object> testClass;
private final Class<? extends Object> testClass;
TestPrintStream(Object testInstance) {
super(new ByteArrayOutputStream());

View File

@@ -71,7 +71,7 @@ public class ImagePackager extends Packager {
*/
private static class DelegatingJarWriter extends AbstractJarWriter {
private BiConsumer<ZipEntry, EntryWriter> exporter;
private final BiConsumer<ZipEntry, EntryWriter> exporter;
DelegatingJarWriter(BiConsumer<ZipEntry, EntryWriter> exporter) {
this.exporter = exporter;

View File

@@ -31,7 +31,7 @@ import org.springframework.util.StringUtils;
*/
public class JavaExecutable {
private File file;
private final File file;
public JavaExecutable() {
String javaHome = System.getProperty("java.home");

View File

@@ -37,7 +37,7 @@ public class RunProcess {
private static final long JUST_ENDED_LIMIT = 500;
private File workingDirectory;
private final File workingDirectory;
private final String[] command;

View File

@@ -722,9 +722,9 @@ abstract class AbstractPackagerTests<P extends Packager> {
private static final Layer DEFAULT_LAYER = new Layer("default");
private Set<Layer> layers = new LinkedHashSet<>();
private final Set<Layer> layers = new LinkedHashSet<>();
private Map<String, Layer> libraries = new HashMap<>();
private final Map<String, Layer> libraries = new HashMap<>();
TestLayers() {
this.layers.add(DEFAULT_LAYER);

View File

@@ -30,7 +30,7 @@ import static org.mockito.Mockito.mock;
*/
class ImplicitLayerResolverTests {
private Layers layers = Layers.IMPLICIT;
private final Layers layers = Layers.IMPLICIT;
@Test
void iteratorReturnsLayers() {

View File

@@ -60,7 +60,7 @@ class SizeCalculatingEntryWriterTests {
private static class TestEntryWriter implements EntryWriter {
private byte[] bytes;
private final byte[] bytes;
TestEntryWriter(int size) {
this.bytes = new byte[size];

View File

@@ -49,7 +49,7 @@ public class ExplodedArchive implements Archive {
private final boolean recursive;
private File manifestFile;
private final File manifestFile;
private Manifest manifest;
@@ -147,7 +147,7 @@ public class ExplodedArchive implements Archive {
private FileEntry current;
private String rootUrl;
private final String rootUrl;
AbstractIterator(File root, boolean recursive, EntryFilter searchFilter, EntryFilter includeFilter) {
this.root = root;

View File

@@ -40,7 +40,7 @@ class JarEntry extends java.util.jar.JarEntry implements FileHeader {
private final JarFile jarFile;
private long localHeaderOffset;
private final long localHeaderOffset;
private volatile JarEntryCertification certification;

View File

@@ -79,9 +79,9 @@ public class JarFile extends AbstractJarFile implements Iterable<java.util.jar.J
private String urlString;
private JarFileEntries entries;
private final JarFileEntries entries;
private Supplier<Manifest> manifestSupplier;
private final Supplier<Manifest> manifestSupplier;
private SoftReference<Manifest> manifest;

View File

@@ -37,7 +37,7 @@ import java.security.Permission;
*/
final class JarURLConnection extends java.net.JarURLConnection {
private static ThreadLocal<Boolean> useFastExceptions = new ThreadLocal<>();
private static final ThreadLocal<Boolean> useFastExceptions = new ThreadLocal<>();
private static final FileNotFoundException FILE_NOT_FOUND_EXCEPTION = new FileNotFoundException(
"Jar file or entry not found");

View File

@@ -90,7 +90,7 @@ class CentralDirectoryParserTests {
static class Collector implements CentralDirectoryVisitor {
private List<CentralDirectoryFileHeader> headers = new ArrayList<>();
private final List<CentralDirectoryFileHeader> headers = new ArrayList<>();
@Override
public void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData) {

View File

@@ -62,7 +62,7 @@ class ArtifactsLibrariesTests {
private Set<Artifact> artifacts;
private File file = new File(".");
private final File file = new File(".");
private ArtifactsLibraries libs;

View File

@@ -49,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class PropertiesMigrationReporterTests {
private ConfigurableEnvironment environment = new MockEnvironment();
private final ConfigurableEnvironment environment = new MockEnvironment();
@Test
void reportIsNullWithNoMatchingKeys() {