Merge pull request #2077 from OpenRefine/issue-2076

Fix NPE in StandardReconConfig.
This commit is contained in:
Antonin Delpeuch 2019-07-09 09:37:40 +02:00 committed by GitHub
commit ab605dcaaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -567,7 +567,7 @@ public class StandardReconConfig extends ReconConfig {
* the cell value to compare the reconciliation data to * the cell value to compare the reconciliation data to
*/ */
public void computeFeatures(Recon recon, String text) { public void computeFeatures(Recon recon, String text) {
if (recon.candidates != null && !recon.candidates.isEmpty()) { if (recon.candidates != null && !recon.candidates.isEmpty() && text != null) {
ReconCandidate candidate = recon.candidates.get(0); ReconCandidate candidate = recon.candidates.get(0);
recon.setFeature(Recon.Feature_nameMatch, text.equalsIgnoreCase(candidate.name)); recon.setFeature(Recon.Feature_nameMatch, text.equalsIgnoreCase(candidate.name));

View File

@ -345,4 +345,15 @@ public class StandardReconConfigTests extends RefineTest {
stub.computeFeatures(recon, "my string"); stub.computeFeatures(recon, "my string");
assertNotNull(recon.features); assertNotNull(recon.features);
} }
/**
* Should not happen, but added for extra safety
*/
@Test
public void testComputeFeaturesNullText() {
StandardReconConfigStub stub = new StandardReconConfigStub();
Recon recon = stub.createNewRecon(2384738L);
stub.computeFeatures(recon, null);
assertNotNull(recon.features);
}
} }