Source:
<code>private AnalyzeSentimentResult convertToTextSentimentResult(final DocumentSentiment documentSentiment) { final TextSentimentClass documentSentimentClass = TextSentimentClass.fromString(documentSentiment. getSentiment().toString()); <START> if (documentSentimentClass == null) { <END> throw logger.logExceptionAsWarning( new RuntimeException(String.format("'%s' is not valid text sentiment.", documentSentiment.getSentiment()))); } final SentimentConfidenceScorePerLabel confidenceScorePerLabel = documentSentiment.getDocumentScores(); final List<TextSentiment> sentenceSentimentTexts = documentSentiment.getSentences().stream() .map(sentenceSentiment -> { TextSentimentClass sentimentClass = TextSentimentClass.fromString(sentenceSentiment .getSentiment().toString()); if (sentimentClass == null) { throw logger.logExceptionAsWarning( new RuntimeException(String.format("'%s' is not valid text sentiment.", sentenceSentiment.getSentiment()))); } SentimentConfidenceScorePerLabel confidenceScorePerSentence = sentenceSentiment.getSentenceScores(); return new TextSentiment(sentimentClass, confidenceScorePerSentence.getNegative(), confidenceScorePerSentence.getNeutral(), confidenceScorePerSentence.getPositive(), sentenceSentiment.getLength(), sentenceSentiment.getOffset()); }).collect(Collectors.toList()); return new AnalyzeSentimentResult(documentSentiment.getId(), documentSentiment.getStatistics() == null ? null : convertToTextDocumentStatistics(documentSentiment.getStatistics()), null, new TextSentiment(documentSentimentClass, confidenceScorePerLabel.getNegative(), confidenceScorePerLabel.getNeutral(), confidenceScorePerLabel.getPositive(), sentenceSentimentTexts.stream().mapToInt(TextSentiment::getLength).sum(), 0), sentenceSentimentTexts); }</code><technical_language>This happen if service returned invalid Sentiment type correct? Is this a good spot throw a Runtime exception if service failed? skip result, log a warning, continue processing other responses</technical_language>

Target:
private AnalyzeSentimentResult convertToTextSentimentResult(final DocumentSentiment documentSentiment) { final TextSentimentClass documentSentimentClass = TextSentimentClass.fromString(documentSentiment. getSentiment().toString()); if (documentSentimentClass == null) { logger.logExceptionAsWarning( new RuntimeException(String.format("'%s' is not valid text sentiment.", documentSentiment.getSentiment()))); } final SentimentConfidenceScorePerLabel confidenceScorePerLabel = documentSentiment.getDocumentScores(); final List<TextSentiment> sentenceSentimentTexts = documentSentiment.getSentences().stream() .map(sentenceSentiment -> { TextSentimentClass sentimentClass = TextSentimentClass.fromString(sentenceSentiment .getSentiment().toString()); if (sentimentClass == null) { logger.logExceptionAsWarning( new RuntimeException(String.format("'%s' is not valid text sentiment.", sentenceSentiment.getSentiment()))); } SentimentConfidenceScorePerLabel confidenceScorePerSentence = sentenceSentiment.getSentenceScores(); return new TextSentiment(sentimentClass, confidenceScorePerSentence.getNegative(), confidenceScorePerSentence.getNeutral(), confidenceScorePerSentence.getPositive(), sentenceSentiment.getLength(), sentenceSentiment.getOffset()); }).collect(Collectors.toList()); return new AnalyzeSentimentResult(documentSentiment.getId(), documentSentiment.getStatistics() == null ? null : convertToTextDocumentStatistics(documentSentiment.getStatistics()), null, new TextSentiment(documentSentimentClass, confidenceScorePerLabel.getNegative(), confidenceScorePerLabel.getNeutral(), confidenceScorePerLabel.getPositive(), sentenceSentimentTexts.stream().mapToInt(TextSentiment::getLength).sum(), 0), sentenceSentimentTexts); }