Skip to content

[TIKA-2392] Fix the rest of potential bugs and 2 new ones that may trigger NullPointerException + add test case #579

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion tika-app/src/main/java/org/apache/tika/gui/TikaGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ public File requestSave(String embeddedName) throws IOException {

int splitAt = embeddedName.lastIndexOf('.');
if (splitAt > 0) {
embeddedName.substring(splitAt);
embeddedName = embeddedName.substring(splitAt);
}

File tmp = Files.createTempFile("tika-embedded-", suffix).toFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public void setUp() throws Exception {
testDirectory = tempDir;
System.out.println(testDirectory.toAbsolutePath());
try (InputStream is = this.getClass().getResourceAsStream(TEST_CLASSPATH)) {
assert is != null;
Files.copy(is, testDirectory.resolve(TEST_HTML));
}
try (InputStream is = this.getClass().getResourceAsStream(TEST_CLASSPATH)) {
assert is != null;
Files.copy(is, testDirectory.resolve(TEST_UNRECOGNISED_EXTENSION));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public String getFilter() {
* Default value is triangle.
*/
public void setFilter(String filter) {
if (filter.equals(null)) {
if (filter == null) {
throw new IllegalArgumentException(
"Filter value cannot be null. Valid values are point, hermite, " +
"cubic, box, gaussian, catrom, triangle, quadratic and mitchell.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
*/
package org.apache.tika.parser.ocr;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
Expand All @@ -31,6 +26,8 @@
import org.apache.tika.config.TikaConfig;
import org.apache.tika.parser.CompositeParser;

import static org.junit.jupiter.api.Assertions.*;

public class TesseractOCRConfigTest extends TikaTest {

@Test
Expand All @@ -46,7 +43,7 @@ public void testNoConfig() throws Exception {
assertEquals("gray", config.getColorspace(), "Invalid default colorpsace value");
assertEquals("triangle", config.getFilter(), "Invalid default filter value");
assertEquals(200, config.getResize(), "Invalid default resize value");
assertEquals(false, config.isApplyRotation(), "Invalid default applyRotation value");
assertFalse(config.isApplyRotation(), "Invalid default applyRotation value");
}

@Test
Expand All @@ -67,7 +64,7 @@ public void testPartialConfig() throws Exception {
assertEquals(8, config.getDepth(), "Invalid overridden depth value");
assertEquals("box", config.getFilter(), "Invalid overridden filter value");
assertEquals(300, config.getResize(), "Invalid overridden resize value");
assertEquals(false, config.isApplyRotation(), "Invalid default applyRotation value");
assertFalse(config.isApplyRotation(), "Invalid default applyRotation value");
}

@Test
Expand All @@ -89,7 +86,7 @@ public void testFullConfig() throws Exception {
assertEquals(8, config.getDepth(), "Invalid overridden depth value");
assertEquals("box", config.getFilter(), "Invalid overridden filter value");
assertEquals(300, config.getResize(), "Invalid overridden resize value");
assertEquals(true, config.isApplyRotation(), "Invalid default applyRotation value");
assertTrue(config.isApplyRotation(), "Invalid default applyRotation value");
}

@Test
Expand Down Expand Up @@ -250,6 +247,14 @@ public void testBadColorSpace() {
});
}

@Test
public void testNullFilter() {
TesseractOCRConfig config = new TesseractOCRConfig();
assertThrows(IllegalArgumentException.class, () -> {
config.setFilter(null);
});
}

@Test
public void testUpdatingConfigs() throws Exception {
TesseractOCRConfig configA = new TesseractOCRConfig();
Expand Down