Skip to content

Commit bec0ebf

Browse files
committed
Enable and fix Java compiler warnings.
- metafacture-commons/src/main/java/org/metafacture/commons/reflection/ConfigurableClass.java:203: warning: [unchecked] unchecked method invocation: method valueOf in class Enum is applied to given types - metafacture-biblio/src/main/java/org/metafacture/biblio/ComarcXmlHandler.java:105: warning: [fallthrough] possible fall-through into case - metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Encoder.java:74: warning: [static] static variable should be qualified by type name, RecordFormat, instead of by an expression - metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Encoder.java:160: warning: [static] static variable should be qualified by type name, RecordFormat, instead of by an expression - metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/CloseSuppressorTest.java:34: warning: [unchecked] unchecked conversion - metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaRecordsReader.java:81: warning: [fallthrough] possible fall-through into case - metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/pojo/PojoEncoderTest.java:260: warning: [unchecked] unchecked cast - metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java:50: warning: [deprecation] GenericXmlHandler(String) in GenericXmlHandler has been deprecated
1 parent 8bb0808 commit bec0ebf

File tree

8 files changed

+26
-6
lines changed

8 files changed

+26
-6
lines changed

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,14 @@ subprojects {
6464
targetCompatibility = 1.8
6565

6666
tasks.withType(JavaCompile) {
67+
'all -processing -rawtypes -serial'.split().each {
68+
options.compilerArgs << "-Xlint:${it}"
69+
}
70+
71+
options.compilerArgs << '-Werror'
6772
options.encoding = 'UTF-8'
6873
}
74+
6975
task sourceJar(type: Jar) {
7076
dependsOn tasks.classes
7177
from sourceSets.main.allJava

metafacture-biblio/src/main/java/org/metafacture/biblio/ComarcXmlHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) {
8989
}
9090

9191
@Override
92+
@SuppressWarnings("fallthrough")
9293
public void endElement(final String uri, final String localName,
9394
final String qName) throws SAXException {
9495
if (SUBFIELD.equals(localName)) {

metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Encoder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.metafacture.biblio.marc21;
1818

1919
import org.metafacture.biblio.iso2709.RecordBuilder;
20+
import org.metafacture.biblio.iso2709.RecordFormat;
2021
import org.metafacture.framework.FluxCommand;
2122
import org.metafacture.framework.FormatException;
2223
import org.metafacture.framework.ObjectReceiver;
@@ -71,7 +72,7 @@
7172
public final class Marc21Encoder extends
7273
DefaultStreamPipe<ObjectReceiver<String>> {
7374

74-
private static final int NAME_LENGTH = Marc21Constants.MARC21_FORMAT.TAG_LENGTH +
75+
private static final int NAME_LENGTH = RecordFormat.TAG_LENGTH +
7576
Marc21Constants.MARC21_FORMAT.getIndicatorLength();
7677

7778
private final RecordBuilder builder;
@@ -157,7 +158,7 @@ private void startField(final String name) {
157158
if (name.length() != NAME_LENGTH) {
158159
throw new FormatException("invalid entity name: " + name);
159160
}
160-
final char[] tag = new char[Marc21Constants.MARC21_FORMAT.TAG_LENGTH];
161+
final char[] tag = new char[RecordFormat.TAG_LENGTH];
161162
final char[] indicators = new char[Marc21Constants.MARC21_FORMAT.getIndicatorLength()];
162163
name.getChars(0, tag.length, tag, 0);
163164
name.getChars(tag.length, name.length(), indicators, 0);

metafacture-commons/src/main/java/org/metafacture/commons/reflection/ConfigurableClass.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private void applySetters(final T target, final Map<String, String> setterValues
188188
}
189189
}
190190

191-
private Object convertValue(final String value, final Class<?> type) {
191+
private <T extends Enum<T>> Object convertValue(final String value, final Class<?> type) {
192192
final Object result;
193193

194194
if (type == boolean.class) {
@@ -199,7 +199,7 @@ else if (type == int.class) {
199199
}
200200
else if (type.isEnum()) {
201201
@SuppressWarnings("unchecked") // protected by type.isEnum() check
202-
final Class<Enum> enumType = (Class<Enum>) type;
202+
final Class<T> enumType = (Class<T>) type;
203203
result = Enum.valueOf(enumType, value.toUpperCase());
204204
}
205205
else {

metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/CloseSuppressorTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
package org.metafacture.flowcontrol;
1818

19+
import org.junit.Rule;
1920
import org.junit.Test;
2021
import org.metafacture.framework.ObjectReceiver;
22+
import org.mockito.Mock;
2123
import org.mockito.Mockito;
24+
import org.mockito.junit.MockitoJUnit;
25+
import org.mockito.junit.MockitoRule;
2226

2327
/**
2428
* Tests for class {@link CloseSuppressor}.
@@ -28,10 +32,15 @@
2832
*/
2933
public final class CloseSuppressorTest {
3034

35+
@Rule
36+
public final MockitoRule mockitoRule = MockitoJUnit.rule();
37+
38+
@Mock
39+
private ObjectReceiver<Object> receiver;
40+
3141
@Test
3242
public void testSuppression() {
3343
final CloseSuppressor<Object> supressor = new CloseSuppressor<>(3);
34-
final ObjectReceiver<Object> receiver = Mockito.mock(ObjectReceiver.class);
3544
supressor.setReceiver(receiver);
3645
supressor.closeStream();
3746
supressor.closeStream();

metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaRecordsReader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public FormetaRecordsReader() {
5151
}
5252

5353
@Override // checkstyle-disable-line CyclomaticComplexity
54+
@SuppressWarnings("fallthrough")
5455
public void process(final Reader reader) {
5556
assert !isClosed();
5657

metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/pojo/PojoEncoderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ public void shouldEncodeEntityStreamToPojoWithSimplePojoMap() {
254254
.stringField2);
255255
}
256256

257+
@SuppressWarnings("unchecked")
257258
private <T> ObjectReceiver<T> createObjectReceiverMock() {
258259
// There is no type safe to create a mock with Mockito#mock(Class).
259260
// Hence, we have to use an unchecked cast here:

metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public final class GenericXMLHandlerTest {
4747
@Before
4848
public void setup() {
4949
MockitoAnnotations.initMocks(this);
50-
genericXmlHandler = new GenericXmlHandler("record");
50+
genericXmlHandler = new GenericXmlHandler();
51+
genericXmlHandler.setRecordTagName("record");
5152
genericXmlHandler.setReceiver(receiver);
5253
}
5354

0 commit comments

Comments
 (0)