Skip to content

Commit 8b7ed8c

Browse files
healqqclaude
andcommitted
fix: allow a null target language in rephraseText() (AX-138)
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 71b6616 commit 8b7ed8c

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
- Fixed the doc comments of `LanguageCode.English` and
3434
`LanguageCode.Portuguese`, which claimed they may only be used as source
3535
languages.
36+
- `rephraseText()` no longer throws a `NullPointerException` when the target
37+
language is `null`.
3638
- `getLanguages()` no longer sends a `POST` request to `/v2/languages`; it
3739
now sends `GET`.
3840

‎deepl-java/src/main/java/com/deepl/api/DeepLClient.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,8 +1826,10 @@ private void validateParameter(String paramName, String value) throws IllegalArg
18261826

18271827
protected static ArrayList<KeyValuePair<String, String>> createWriteHttpParams(
18281828
List<String> texts, @Nullable String targetLang, @Nullable TextRephraseOptions options) {
1829-
targetLang = LanguageCode.standardize(targetLang);
1830-
checkValidLanguages(null, targetLang);
1829+
if (targetLang != null) {
1830+
targetLang = LanguageCode.standardize(targetLang);
1831+
checkValidLanguages(null, targetLang);
1832+
}
18311833

18321834
ArrayList<KeyValuePair<String, String>> params = new ArrayList<>();
18331835
if (targetLang != null) {

‎deepl-java/src/test/java/com/deepl/api/CorrectTextTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void testTextArray() throws DeepLException, InterruptedException {
3232
@Test
3333
void testEmptyText() {
3434
DeepLClient client = createDeepLClient();
35-
Assertions.assertThrows(IllegalArgumentException.class, () -> client.correctText("", "en-US"));
35+
Assertions.assertThrows(IllegalArgumentException.class, () -> client.correctText("", null));
3636
}
3737

3838
protected void checkSanityOfImprovements(

‎deepl-java/src/test/java/com/deepl/api/RephraseTextTest.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.util.*;
77
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.Assumptions;
89
import org.junit.jupiter.api.Test;
910

1011
public class RephraseTextTest extends TestBase {
@@ -26,6 +27,15 @@ void testBareEnglishAndPortugueseTargetLanguages() {
2627
() -> client.rephraseText(exampleText.get("pt"), LanguageCode.Portuguese, null));
2728
}
2829

30+
@Test
31+
void testNullTargetLang() throws DeepLException, InterruptedException {
32+
// deepl-mock requires target_lang for rephrase although the API does not.
33+
Assumptions.assumeFalse(isMockServer);
34+
DeepLClient client = createDeepLClient();
35+
WriteResult result = client.rephraseText(exampleText.get("en"), null, null);
36+
Assertions.assertNotNull(result.getText());
37+
}
38+
2939
@Test
3040
void testTextArray() throws DeepLException, InterruptedException {
3141
DeepLClient client = createDeepLClient();

0 commit comments

Comments
 (0)