Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix modernizer #9824

Merged
merged 4 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,14 @@ checkstyle {
sourceSets = []
}

modernizer {
failOnViolations = false
includeTestClasses = true
exclusions = [
'java/util/Optional.get:()Ljava/lang/Object;'
]
}

// Release tasks
task deleteInstallerTemp(type: Delete) {
delete "$buildDir/installer"
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/push/PushToLyx.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

import org.jabref.gui.DialogService;
Expand Down Expand Up @@ -86,7 +87,7 @@ public void pushEntries(BibDatabaseContext database, final List<BibEntry> entrie
final File lyxpipe = lp;

JabRefExecutorService.INSTANCE.executeAndWait(() -> {
try (FileWriter fw = new FileWriter(lyxpipe); BufferedWriter lyxOut = new BufferedWriter(fw)) {
try (FileWriter fw = new FileWriter(lyxpipe, StandardCharsets.UTF_8); BufferedWriter lyxOut = new BufferedWriter(fw)) {
String citeStr = "LYXCMD:sampleclient:citation-insert:" + keyString;
lyxOut.write(citeStr + "\n");
} catch (IOException excep) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void doAPILimiting(String identifier) {
} // mEDRA does not explicit an API rating

LOGGER.trace(String.format("Thread %s, searching for DOI '%s', waited %.2fs because of API rate limiter",
Thread.currentThread().getId(), identifier, waitingTime));
Thread.currentThread().threadId(), identifier, waitingTime));
}
} catch (IOException e) {
LOGGER.warn("Could not limit DOI API access rate", e);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/l10n/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public static Optional<Locale> convertToSupportedLocale(Language language) {
String[] languageParts = language.getId().split("_");
Locale locale;
if (languageParts.length == 1) {
locale = new Locale(languageParts[0]);
locale = Locale.of(languageParts[0]);
} else if (languageParts.length == 2) {
locale = new Locale(languageParts[0], languageParts[1]);
locale = Locale.of(languageParts[0], languageParts[1]);
} else {
locale = Locale.ENGLISH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void performSearchWithoutFetchers() throws Exception {

List<BibEntry> result = fetcher.performSearch("quantum");

Assertions.assertEquals(result, Collections.EMPTY_LIST);
Assertions.assertEquals(result, Collections.emptyList());
}

@ParameterizedTest(name = "Perform Search on empty query.")
Expand All @@ -60,7 +60,7 @@ public void performSearchOnEmptyQuery(Set<SearchBasedFetcher> fetchers) throws E

List<BibEntry> queryResult = compositeFetcher.performSearch("");

Assertions.assertEquals(queryResult, Collections.EMPTY_LIST);
Assertions.assertEquals(queryResult, Collections.emptyList());
}

@ParameterizedTest(name = "Perform search on query \"quantum\". Using the CompositeFetcher of the following " +
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/org/jabref/logic/integrity/UTF8CheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

public class UTF8CheckerTest {

private static final Charset GBK = Charset.forName("GBK");
private final BibEntry entry = new BibEntry();

/**
Expand All @@ -42,7 +43,7 @@ void fieldAcceptsUTF8() {
@Test
void fieldDoesNotAcceptUmlauts() throws UnsupportedEncodingException {
UTF8Checker checker = new UTF8Checker(Charset.forName("GBK"));
String NonUTF8 = new String("你好,这条语句使用GBK字符集".getBytes(), "GBK");
String NonUTF8 = new String("你好,这条语句使用GBK字符集".getBytes(StandardCharsets.UTF_8), GBK);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure that this is intended here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test goes through. JavaDoc on getBytes says that default Charset is used. Maybe be platform dependend. Java switched to UTF8 recently.

See the last parameter GBK which recodes the bytes to GKB leading to non-utf. Therefore, I think, it works.

entry.setField(StandardField.MONTH, NonUTF8);
assertEquals(List.of(new IntegrityMessage("Non-UTF-8 encoded field found", entry, StandardField.MONTH)), checker.check(entry));
}
Expand All @@ -56,8 +57,8 @@ void fieldDoesNotAcceptUmlauts() throws UnsupportedEncodingException {
*/
@Test
void NonUTF8EncodingCheckerTest() throws UnsupportedEncodingException {
String NonUTF8 = new String("你好,这条语句使用GBK字符集".getBytes(), "GBK");
assertFalse(UTF8Checker.UTF8EncodingChecker(NonUTF8.getBytes("GBK")));
String NonUTF8 = new String("你好,这条语句使用GBK字符集".getBytes(StandardCharsets.UTF_8), GBK);
assertFalse(UTF8Checker.UTF8EncodingChecker(NonUTF8.getBytes(GBK)));
}

/**
Expand All @@ -66,7 +67,7 @@ void NonUTF8EncodingCheckerTest() throws UnsupportedEncodingException {
*/
@Test
void UTF8EncodingCheckerTest() {
String UTF8Demo = new String("你好,这条语句使用GBK字符集".getBytes(), StandardCharsets.UTF_8);
String UTF8Demo = new String("你好,这条语句使用GBK字符集".getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);
assertTrue(UTF8Checker.UTF8EncodingChecker(UTF8Demo.getBytes(StandardCharsets.UTF_8)));
}
}
4 changes: 2 additions & 2 deletions src/test/java/org/jabref/logic/l10n/LanguageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class LanguageTest {

@Test
void convertKnownLanguageOnly() {
assertEquals(Optional.of(new Locale("en")), Language.convertToSupportedLocale(Language.ENGLISH));
assertEquals(Optional.of(Locale.of("en")), Language.convertToSupportedLocale(Language.ENGLISH));
}

@Test
void convertKnownLanguageAndCountryCorrect() {
// Language and country code have to be separated see: https://stackoverflow.com/a/3318598
assertEquals(Optional.of(new Locale("pt", "BR")), Language.convertToSupportedLocale(Language.BRAZILIAN_PORTUGUESE));
assertEquals(Optional.of(Locale.of("pt", "BR")), Language.convertToSupportedLocale(Language.BRAZILIAN_PORTUGUESE));
}

@Test
Expand Down