Skip to content

Commit 1a5e003

Browse files
committed
Disallow static, non-final variables. (#577)
1 parent 01a7351 commit 1a5e003

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

config/checkstyle/checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
<module name="SimplifyBooleanReturn"/>
151151
<module name="StaticVariableName">
152152
<!-- disallow static, non-final variables -->
153-
<!--<property name="format" value="^$"/>-->
153+
<property name="format" value="^$"/>
154154
</module>
155155
<module name="StringLiteralEquality"/>
156156
<module name="SuperClone"/>

metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaEncoder.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public final class PicaEncoder extends DefaultStreamPipe<ObjectReceiver<String>>
6262
private static final String FIELD_NAME_PATTERN_STRING = "\\d{3}.(/..)?";
6363
private static final Pattern FIELD_NAME_PATTERN = Pattern.compile(FIELD_NAME_PATTERN_STRING);
6464

65-
private static StringBuilder builder = new StringBuilder(); //Result of the encoding process
65+
private static final StringBuilder BUILDER = new StringBuilder(); // Result of the encoding process
6666

6767
private boolean entityOpen; // Flag to inform whether an entity is opened.
6868
private boolean idnControlSubField; // Flag to inform whether it is the 003@ field.
@@ -80,7 +80,7 @@ public PicaEncoder() {
8080
public void startRecord(final String recordId) {
8181
// the name is a idn, which should be found in the encoded data under 003@.
8282
//any rest of the previous record is cleared before the new begins.
83-
builder.setLength(0);
83+
BUILDER.setLength(0);
8484
this.id = recordId;
8585
//Now an entity can be opened. But no literal is allowed.
8686
this.entityOpen = false;
@@ -118,7 +118,7 @@ public void startEntity(final String name) {
118118
if (entityOpen) { //No nested entities are allowed in pica+.
119119
throw new FormatException(name);
120120
}
121-
builder.append(name.trim() + " ");
121+
BUILDER.append(name.trim() + " ");
122122

123123
idnControlSubField = !ignoreRecordId && FIELD_IDN_INTERN.equals(name.trim());
124124
//Now literals can be opened but no more entities.
@@ -142,28 +142,28 @@ public void literal(final String name, final String value) {
142142
}
143143
idnControlSubField = false; //only one record ID will be checked.
144144
}
145-
builder.append(SUB_DELIMITER);
146-
builder.append(name);
147-
builder.append(valueNew);
145+
BUILDER.append(SUB_DELIMITER);
146+
BUILDER.append(name);
147+
BUILDER.append(valueNew);
148148
}
149149

150150
@Override
151151
public void endEntity() {
152-
builder.append(FIELD_DELIMITER);
152+
BUILDER.append(FIELD_DELIMITER);
153153
//Now an entity can be opened. But no literal is allowed.
154154
this.entityOpen = false;
155155
}
156156

157157
@Override
158158
public void endRecord() {
159-
getReceiver().process(builder.toString());
159+
getReceiver().process(BUILDER.toString());
160160
//No literal is allowed.
161161
this.entityOpen = false;
162162
}
163163

164164
@Override
165165
protected void onResetStream() {
166-
builder.setLength(0);
166+
BUILDER.setLength(0);
167167
}
168168

169169
}

metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public class MarcXmlEncoderTest {
4646
private static final String XML_MARC_COLLECTION_END_TAG = "</marc:collection>";
4747
private static final String RECORD_ID = "92005291";
4848

49-
private static StringBuilder resultCollector;
50-
private static int resultCollectorsResetStreamCount;
51-
private static MarcXmlEncoder encoder;
49+
private StringBuilder resultCollector;
50+
private int resultCollectorsResetStreamCount;
51+
private MarcXmlEncoder encoder;
5252

5353
public MarcXmlEncoderTest() {
5454
}

metafacture-io/src/test/java/org/metafacture/io/HttpOpenerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ public final class HttpOpenerTest {
5959
private static final String REQUEST_BODY = "request body";
6060
private static final String RESPONSE_BODY = "response bödy"; // UTF-8
6161

62-
private static byte[] gzippedResponseBody;
62+
private static byte[] GZIPPED_RESPONSE_BODY; // checkstyle-disable-line StaticVariableName
6363

6464
static {
6565
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
6666
final GZIPOutputStream gzip = new GZIPOutputStream(out);
6767
gzip.write(RESPONSE_BODY.getBytes("UTF-8"));
6868
gzip.close();
6969

70-
gzippedResponseBody = out.toByteArray();
70+
GZIPPED_RESPONSE_BODY = out.toByteArray();
7171
}
7272
catch (final IOException e) {
7373
e.printStackTrace();
@@ -290,7 +290,7 @@ public void shouldPerformGetRequestWithErrorResponseAndWithoutErrorPrefixParamet
290290
@Test
291291
public void shouldPerformGetRequestWithGzippedContentEncoding() throws IOException {
292292
shouldPerformRequest(TEST_URL, HttpOpener.Method.GET, (o, u) -> o.setAcceptEncoding("gzip"),
293-
null, null, WireMock.ok().withBody(gzippedResponseBody).withHeader(HttpOpener.CONTENT_ENCODING_HEADER, "gzip"), RESPONSE_BODY);
293+
null, null, WireMock.ok().withBody(GZIPPED_RESPONSE_BODY).withHeader(HttpOpener.CONTENT_ENCODING_HEADER, "gzip"), RESPONSE_BODY);
294294
}
295295

296296
private void shouldPerformRequest(final String input, final HttpOpener.Method method, final BiConsumer<HttpOpener, String> consumer, final String... headers) throws IOException {

0 commit comments

Comments
 (0)