[core] Fix NPE on cache

- Resolves #600
This commit is contained in:
Juan Martín Sotuyo Dodero
2017-09-07 12:05:58 -03:00
parent 6d8c41113f
commit 96d2983f4f
2 changed files with 11 additions and 7 deletions

View File

@@ -145,15 +145,19 @@ public final class CachedRuleViolation implements RuleViolation {
*/
/* package */ static void storeToStream(final DataOutputStream stream,
final RuleViolation violation) throws IOException {
stream.writeUTF(violation.getDescription());
stream.writeUTF(violation.getRule().getRuleClass());
stream.writeUTF(getValueOrEmpty(violation.getDescription()));
stream.writeUTF(getValueOrEmpty(violation.getRule().getRuleClass()));
stream.writeInt(violation.getBeginLine());
stream.writeInt(violation.getBeginColumn());
stream.writeInt(violation.getEndLine());
stream.writeInt(violation.getEndColumn());
stream.writeUTF(violation.getPackageName());
stream.writeUTF(violation.getClassName());
stream.writeUTF(violation.getMethodName());
stream.writeUTF(violation.getVariableName());
stream.writeUTF(getValueOrEmpty(violation.getPackageName()));
stream.writeUTF(getValueOrEmpty(violation.getClassName()));
stream.writeUTF(getValueOrEmpty(violation.getMethodName()));
stream.writeUTF(getValueOrEmpty(violation.getVariableName()));
}
private static String getValueOrEmpty(final String value) {
return value == null ? "" : value;
}
}

View File

@@ -91,7 +91,7 @@ public class FileAnalysisCacheTest {
final FileAnalysisCache cache = new FileAnalysisCache(newCacheFile);
cache.isUpToDate(sourceFile);
final RuleViolation rv = mock(RuleViolation.class, Mockito.RETURNS_SMART_NULLS);
final RuleViolation rv = mock(RuleViolation.class);
when(rv.getFilename()).thenReturn(sourceFile.getPath());
final net.sourceforge.pmd.Rule rule = mock(net.sourceforge.pmd.Rule.class, Mockito.RETURNS_SMART_NULLS);
when(rv.getRule()).thenReturn(rule);