[ 
https://issues.apache.org/jira/browse/STORM-3190?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16576392#comment-16576392
 ] 

Zhengdai Hu edited comment on STORM-3190 at 8/10/18 3:18 PM:
-------------------------------------------------------------

We can further simplify this.


{code:java}
    private long lastModifiedTimeWorkerLogdir(File logDir) {
        long dirModified = logDir.lastModified();
        try (DirectoryStream<Path> dirStream = 
directoryCleaner.getStreamForDirectory(logDir)) {
            if (dirStream != null) {
                try {
                    return StreamSupport.stream(dirStream.spliterator(), false)
                            .mapToLong(path -> path.toFile().lastModified())
                            .reduce(dirModified, Math::max);
                } catch (Exception ex) {
                    LOG.error(ex.getMessage(), ex);
                }
            }
        } catch (IOException ignored) {}
        return dirModified;
    }
{code}



was (Author: zhengdai):
We can further simplify this.


{code:java}
    private long lastModifiedTimeWorkerLogdir(File logDir) {
        long dirModified = logDir.lastModified();
        try (DirectoryStream<Path> dirStream = 
directoryCleaner.getStreamForDirectory(logDir)) {
            if (dirStream != null) {
                try {
                    return StreamSupport.stream(dirStream.spliterator(), false)
                            .reduce(dirModified, (maximum, path) -> {
                                long curr = path.toFile().lastModified();
                                return curr > maximum ? curr : maximum;
                            }, BinaryOperator.maxBy(Long::compareTo));
                } catch (Exception ex) {
                    LOG.error(ex.getMessage(), ex);
                }
            }
        } catch (IOException ignored) {}
        return dirModified;
    }
{code}


> Unnecessary null check of directory stream in LogCleaner
> --------------------------------------------------------
>
>                 Key: STORM-3190
>                 URL: https://issues.apache.org/jira/browse/STORM-3190
>             Project: Apache Storm
>          Issue Type: Task
>          Components: storm-webapp
>    Affects Versions: 2.0.0
>            Reporter: Stig Rohde Døssing
>            Priority: Trivial
>
> This should be using try-with-resources 
> https://github.com/apache/storm/blob/a1b3e02aab57b4e458b8b5763a0d467852906bb7/storm-webapp/src/main/java/org/apache/storm/daemon/logviewer/utils/LogCleaner.java#L263



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to