Skip to content

Commit 01d21cb

Browse files
OpenRewriteppkarwasz
OpenRewrite
authored andcommitted
Use final whenever possible
1 parent 296e117 commit 01d21cb

File tree

574 files changed

+2477
-2447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

574 files changed

+2477
-2447
lines changed

log4j-1.2-api/src/main/java/org/apache/log4j/Category.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ private void fireRemoveAppenderEvent(final Appender appender) {
319319
}
320320
}
321321

322-
private static Message createMessage(Object message) {
322+
private static Message createMessage(final Object message) {
323323
if (message instanceof String) {
324324
return new SimpleMessage((String) message);
325325
}

log4j-1.2-api/src/main/java/org/apache/log4j/ConsoleAppender.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public boolean requiresLayout() {
112112
* are appended.
113113
* @since 1.2.13
114114
*/
115-
public void setFollow(boolean follow) {
115+
public void setFollow(final boolean follow) {
116116
this.follow = follow;
117117
}
118118

log4j-1.2-api/src/main/java/org/apache/log4j/FileAppender.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public FileAppender() {
7474
* The file will be appended to.
7575
* </p>
7676
*/
77-
public FileAppender(Layout layout, String filename) throws IOException {
77+
public FileAppender(final Layout layout, final String filename) throws IOException {
7878
this(layout, filename, true);
7979
}
8080

@@ -86,7 +86,7 @@ public FileAppender(Layout layout, String filename) throws IOException {
8686
* <code>filename</code> will be truncated before being opened.
8787
* </p>
8888
*/
89-
public FileAppender(Layout layout, String filename, boolean append) throws IOException {
89+
public FileAppender(final Layout layout, final String filename, final boolean append) throws IOException {
9090
this.layout = layout;
9191
this.setFile(filename, append, false, bufferSize);
9292
}
@@ -103,7 +103,7 @@ public FileAppender(Layout layout, String filename, boolean append) throws IOExc
103103
* file.
104104
* </p>
105105
*/
106-
public FileAppender(Layout layout, String filename, boolean append, boolean bufferedIO, int bufferSize) throws IOException {
106+
public FileAppender(final Layout layout, final String filename, final boolean append, final boolean bufferedIO, final int bufferSize) throws IOException {
107107
this.layout = layout;
108108
this.setFile(filename, append, bufferedIO, bufferSize);
109109
}
@@ -194,7 +194,7 @@ protected void reset() {
194194
* Note: Actual opening of the file is made when {@link #activateOptions} is called, not when the options are set.
195195
* </p>
196196
*/
197-
public void setAppend(boolean flag) {
197+
public void setAppend(final boolean flag) {
198198
fileAppend = flag;
199199
}
200200

@@ -205,7 +205,7 @@ public void setAppend(boolean flag) {
205205
* BufferedIO will significatnly increase performance on heavily loaded systems.
206206
*
207207
*/
208-
public void setBufferedIO(boolean bufferedIO) {
208+
public void setBufferedIO(final boolean bufferedIO) {
209209
this.bufferedIO = bufferedIO;
210210
if (bufferedIO) {
211211
immediateFlush = false;
@@ -215,7 +215,7 @@ public void setBufferedIO(boolean bufferedIO) {
215215
/**
216216
* Set the size of the IO buffer.
217217
*/
218-
public void setBufferSize(int bufferSize) {
218+
public void setBufferSize(final int bufferSize) {
219219
this.bufferSize = bufferSize;
220220
}
221221

@@ -228,10 +228,10 @@ public void setBufferSize(int bufferSize) {
228228
* Note: Actual opening of the file is made when {@link #activateOptions} is called, not when the options are set.
229229
* </p>
230230
*/
231-
public void setFile(String file) {
231+
public void setFile(final String file) {
232232
// Trim spaces from both ends. The users probably does not want
233233
// trailing spaces in file names.
234-
String val = file.trim();
234+
final String val = file.trim();
235235
fileName = val;
236236
}
237237

@@ -269,9 +269,9 @@ public synchronized void setFile(String fileName, boolean append, boolean buffer
269269
// attempt to create it and try to create file
270270
// see bug 9150
271271
//
272-
String parentName = new File(fileName).getParent();
272+
final String parentName = new File(fileName).getParent();
273273
if (parentName != null) {
274-
File parentDir = new File(parentName);
274+
final File parentDir = new File(parentName);
275275
if (!parentDir.exists() && parentDir.mkdirs()) {
276276
ostream = new FileOutputStream(fileName, append);
277277
} else {
@@ -299,7 +299,7 @@ public synchronized void setFile(String fileName, boolean append, boolean buffer
299299
*
300300
* This method is overriden by {@link RollingFileAppender}.
301301
*/
302-
protected void setQWForFiles(Writer writer) {
302+
protected void setQWForFiles(final Writer writer) {
303303
this.qw = new QuietWriter(writer, errorHandler);
304304
}
305305
}

log4j-1.2-api/src/main/java/org/apache/log4j/PropertyConfigurator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public void doConfigure(final String fileName, final LoggerRepository loggerRepo
357357
* @param loggerRepository The hierarchy
358358
*/
359359
Configuration doConfigure(final String fileName, final LoggerRepository loggerRepository, final ClassLoader classLoader) {
360-
try (InputStream inputStream = Files.newInputStream(Paths.get(fileName))) {
360+
try (final InputStream inputStream = Files.newInputStream(Paths.get(fileName))) {
361361
return doConfigure(inputStream, loggerRepository, classLoader);
362362
} catch (final Exception e) {
363363
if (e instanceof InterruptedIOException || e instanceof InterruptedException) {
@@ -384,7 +384,7 @@ Configuration doConfigure(final URL url, final LoggerRepository loggerRepository
384384
LogLog.debug("Reading configuration from URL " + url);
385385
try {
386386
final URLConnection urlConnection = UrlConnectionFactory.createConnection(url);
387-
try (InputStream inputStream = urlConnection.getInputStream()) {
387+
try (final InputStream inputStream = urlConnection.getInputStream()) {
388388
return doConfigure(inputStream, loggerRepository, classLoader);
389389
}
390390
} catch (final IOException e) {

log4j-1.2-api/src/main/java/org/apache/log4j/RenderedMessage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class RenderedMessage implements Message {
2828
private final Object object;
2929
private String rendered = null;
3030

31-
public RenderedMessage(ObjectRenderer renderer, Object object) {
31+
public RenderedMessage(final ObjectRenderer renderer, final Object object) {
3232
this.renderer = renderer;
3333
this.object = object;
3434
}

log4j-1.2-api/src/main/java/org/apache/log4j/RollingFileAppender.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public RollingFileAppender() {
6262
* <code>filename</code> will be truncated before being opened.
6363
* </p>
6464
*/
65-
public RollingFileAppender(Layout layout, String filename, boolean append) throws IOException {
65+
public RollingFileAppender(final Layout layout, final String filename, final boolean append) throws IOException {
6666
super(layout, filename, append);
6767
}
6868

@@ -74,7 +74,7 @@ public RollingFileAppender(Layout layout, String filename, boolean append) throw
7474
* The file will be appended to.
7575
* </p>
7676
*/
77-
public RollingFileAppender(Layout layout, String filename) throws IOException {
77+
public RollingFileAppender(final Layout layout, final String filename) throws IOException {
7878
super(layout, filename);
7979
}
8080

@@ -113,7 +113,7 @@ void rollOver() {
113113
File file;
114114

115115
if (qw != null) {
116-
long size = ((CountingQuietWriter) qw).getCount();
116+
final long size = ((CountingQuietWriter) qw).getCount();
117117
LogLog.debug("rolling over count=" + size);
118118
// if operation fails, do not roll again until
119119
// maxFileSize more bytes are written
@@ -182,10 +182,10 @@ void rollOver() {
182182
}
183183
}
184184

185-
public synchronized void setFile(String fileName, boolean append, boolean bufferedIO, int bufferSize) throws IOException {
185+
public synchronized void setFile(final String fileName, final boolean append, final boolean bufferedIO, final int bufferSize) throws IOException {
186186
super.setFile(fileName, append, this.bufferedIO, this.bufferSize);
187187
if (append) {
188-
File f = new File(fileName);
188+
final File f = new File(fileName);
189189
((CountingQuietWriter) qw).setCount(f.length());
190190
}
191191
}
@@ -199,7 +199,7 @@ public synchronized void setFile(String fileName, boolean append, boolean buffer
199199
* when it reaches <code>MaxFileSize</code>.
200200
* </p>
201201
*/
202-
public void setMaxBackupIndex(int maxBackups) {
202+
public void setMaxBackupIndex(final int maxBackups) {
203203
this.maxBackupIndex = maxBackups;
204204
}
205205

@@ -227,11 +227,11 @@ public void setMaximumFileSize(long maxFileSize) {
227227
* kilobytes, megabytes or gigabytes. For example, the value "10KB" will be interpreted as 10240.
228228
* </p>
229229
*/
230-
public void setMaxFileSize(String value) {
230+
public void setMaxFileSize(final String value) {
231231
maxFileSize = OptionConverter.toFileSize(value, maxFileSize + 1);
232232
}
233233

234-
protected void setQWForFiles(Writer writer) {
234+
protected void setQWForFiles(final Writer writer) {
235235
this.qw = new CountingQuietWriter(writer, errorHandler);
236236
}
237237

@@ -240,10 +240,10 @@ protected void setQWForFiles(Writer writer) {
240240
*
241241
* @since 0.9.0
242242
*/
243-
protected void subAppend(LoggingEvent event) {
243+
protected void subAppend(final LoggingEvent event) {
244244
super.subAppend(event);
245245
if (fileName != null && qw != null) {
246-
long size = ((CountingQuietWriter) qw).getCount();
246+
final long size = ((CountingQuietWriter) qw).getCount();
247247
if (size >= maxFileSize && size >= nextRollover) {
248248
rollOver();
249249
}

log4j-1.2-api/src/main/java/org/apache/log4j/WriterAppender.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public WriterAppender() {
7878
* @param layout The Layout.
7979
* @param os The OutputStream.
8080
*/
81-
public WriterAppender(Layout layout, OutputStream os) {
81+
public WriterAppender(final Layout layout, final OutputStream os) {
8282
this(layout, new OutputStreamWriter(os));
8383
}
8484

@@ -92,7 +92,7 @@ public WriterAppender(Layout layout, OutputStream os) {
9292
* @param layout The Layout.
9393
* @param writer The Writer.
9494
*/
95-
public WriterAppender(Layout layout, Writer writer) {
95+
public WriterAppender(final Layout layout, final Writer writer) {
9696
this.layout = layout;
9797
this.setWriter(writer);
9898
}
@@ -121,7 +121,7 @@ public boolean getImmediateFlush() {
121121
*
122122
* @param value the value to set the immediate flush setting to.
123123
*/
124-
public void setImmediateFlush(boolean value) {
124+
public void setImmediateFlush(final boolean value) {
125125
immediateFlush = value;
126126
}
127127

@@ -145,7 +145,7 @@ public void activateOptions() {
145145
* layout.
146146
*/
147147
@Override
148-
public void append(LoggingEvent event) {
148+
public void append(final LoggingEvent event) {
149149

150150
// Reminder: the nesting of calls is:
151151
//
@@ -235,10 +235,10 @@ protected void closeWriter() {
235235
* @param os The OutputStream.
236236
* @return The OutputStreamWriter.
237237
*/
238-
protected OutputStreamWriter createWriter(OutputStream os) {
238+
protected OutputStreamWriter createWriter(final OutputStream os) {
239239
OutputStreamWriter retval = null;
240240

241-
String enc = getEncoding();
241+
final String enc = getEncoding();
242242
if (enc != null) {
243243
try {
244244
retval = new OutputStreamWriter(os, enc);
@@ -260,7 +260,7 @@ public String getEncoding() {
260260
return encoding;
261261
}
262262

263-
public void setEncoding(String value) {
263+
public void setEncoding(final String value) {
264264
encoding = value;
265265
}
266266

@@ -270,7 +270,7 @@ public void setEncoding(String value) {
270270
* underlying {@link QuietWriter} if any.
271271
*/
272272
@Override
273-
public synchronized void setErrorHandler(ErrorHandler eh) {
273+
public synchronized void setErrorHandler(final ErrorHandler eh) {
274274
if (eh == null) {
275275
LOGGER.warn("You have tried to set a null error-handler.");
276276
} else {
@@ -295,7 +295,7 @@ public synchronized void setErrorHandler(ErrorHandler eh) {
295295
*
296296
* @param writer An already opened Writer.
297297
*/
298-
public synchronized void setWriter(Writer writer) {
298+
public synchronized void setWriter(final Writer writer) {
299299
reset();
300300
this.qw = new QuietWriter(writer, errorHandler);
301301
//this.tp = new TracerPrintWriter(qw);
@@ -312,13 +312,13 @@ public synchronized void setWriter(Writer writer) {
312312
*
313313
* @since 0.9.0
314314
*/
315-
protected void subAppend(LoggingEvent event) {
315+
protected void subAppend(final LoggingEvent event) {
316316
this.qw.write(this.layout.format(event));
317317

318318
if (layout.ignoresThrowable()) {
319-
String[] s = event.getThrowableStrRep();
319+
final String[] s = event.getThrowableStrRep();
320320
if (s != null) {
321-
int len = s.length;
321+
final int len = s.length;
322322
for (int i = 0; i < len; i++) {
323323
this.qw.write(s[i]);
324324
this.qw.write(Layout.LINE_SEP);
@@ -360,7 +360,7 @@ protected void reset() {
360360
*/
361361
protected void writeFooter() {
362362
if (layout != null) {
363-
String f = layout.getFooter();
363+
final String f = layout.getFooter();
364364
if (f != null && this.qw != null) {
365365
this.qw.write(f);
366366
this.qw.flush();
@@ -374,7 +374,7 @@ protected void writeFooter() {
374374
*/
375375
protected void writeHeader() {
376376
if (layout != null) {
377-
String h = layout.getHeader();
377+
final String h = layout.getHeader();
378378
if (h != null && this.qw != null) {
379379
this.qw.write(h);
380380
}

log4j-1.2-api/src/main/java/org/apache/log4j/bridge/AppenderAdapter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* Binds a Log4j 1.x Appender to Log4j 2.
3131
*/
32-
public class AppenderAdapter {
32+
public final class AppenderAdapter {
3333

3434
private final Appender appender;
3535
private final Adapter adapter;
@@ -43,7 +43,7 @@ public class AppenderAdapter {
4343
* @param appender a Log4j 1.x appender
4444
* @return a Log4j 2.x appender or {@code null} if the parameter is {@code null}
4545
*/
46-
public static org.apache.logging.log4j.core.Appender adapt(Appender appender) {
46+
public static org.apache.logging.log4j.core.Appender adapt(final Appender appender) {
4747
if (appender instanceof org.apache.logging.log4j.core.Appender) {
4848
return (org.apache.logging.log4j.core.Appender) appender;
4949
}
@@ -60,7 +60,7 @@ public static org.apache.logging.log4j.core.Appender adapt(Appender appender) {
6060
* Constructor.
6161
* @param appender The Appender to wrap.
6262
*/
63-
private AppenderAdapter(Appender appender) {
63+
private AppenderAdapter(final Appender appender) {
6464
this.appender = appender;
6565
final org.apache.logging.log4j.core.Filter appenderFilter = FilterAdapter.adapt(appender.getFilter());
6666
String name = appender.getName();
@@ -82,7 +82,7 @@ protected Adapter(final String name, final Filter filter, final Layout<? extends
8282
}
8383

8484
@Override
85-
public void append(LogEvent event) {
85+
public void append(final LogEvent event) {
8686
appender.doAppend(new LogEventAdapter(event));
8787
}
8888

0 commit comments

Comments
 (0)