Skip to content

Commit

Permalink
Disallow static, non-final variables. (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwinter committed Jan 29, 2025
1 parent 01a7351 commit 1a5e003
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<module name="SimplifyBooleanReturn"/>
<module name="StaticVariableName">
<!-- disallow static, non-final variables -->
<!--<property name="format" value="^$"/>-->
<property name="format" value="^$"/>
</module>
<module name="StringLiteralEquality"/>
<module name="SuperClone"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public final class PicaEncoder extends DefaultStreamPipe<ObjectReceiver<String>>
private static final String FIELD_NAME_PATTERN_STRING = "\\d{3}.(/..)?";
private static final Pattern FIELD_NAME_PATTERN = Pattern.compile(FIELD_NAME_PATTERN_STRING);

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

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

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

@Override
public void endEntity() {
builder.append(FIELD_DELIMITER);
BUILDER.append(FIELD_DELIMITER);
//Now an entity can be opened. But no literal is allowed.
this.entityOpen = false;
}

@Override
public void endRecord() {
getReceiver().process(builder.toString());
getReceiver().process(BUILDER.toString());
//No literal is allowed.
this.entityOpen = false;
}

@Override
protected void onResetStream() {
builder.setLength(0);
BUILDER.setLength(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public class MarcXmlEncoderTest {
private static final String XML_MARC_COLLECTION_END_TAG = "</marc:collection>";
private static final String RECORD_ID = "92005291";

private static StringBuilder resultCollector;
private static int resultCollectorsResetStreamCount;
private static MarcXmlEncoder encoder;
private StringBuilder resultCollector;
private int resultCollectorsResetStreamCount;
private MarcXmlEncoder encoder;

public MarcXmlEncoderTest() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public final class HttpOpenerTest {
private static final String REQUEST_BODY = "request body";
private static final String RESPONSE_BODY = "response bödy"; // UTF-8

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

static {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
final GZIPOutputStream gzip = new GZIPOutputStream(out);
gzip.write(RESPONSE_BODY.getBytes("UTF-8"));
gzip.close();

gzippedResponseBody = out.toByteArray();
GZIPPED_RESPONSE_BODY = out.toByteArray();
}
catch (final IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -290,7 +290,7 @@ public void shouldPerformGetRequestWithErrorResponseAndWithoutErrorPrefixParamet
@Test
public void shouldPerformGetRequestWithGzippedContentEncoding() throws IOException {
shouldPerformRequest(TEST_URL, HttpOpener.Method.GET, (o, u) -> o.setAcceptEncoding("gzip"),
null, null, WireMock.ok().withBody(gzippedResponseBody).withHeader(HttpOpener.CONTENT_ENCODING_HEADER, "gzip"), RESPONSE_BODY);
null, null, WireMock.ok().withBody(GZIPPED_RESPONSE_BODY).withHeader(HttpOpener.CONTENT_ENCODING_HEADER, "gzip"), RESPONSE_BODY);
}

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

0 comments on commit 1a5e003

Please sign in to comment.