Github user alopresto commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/328#discussion_r67093804
  
    --- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java
 ---
    @@ -154,30 +164,21 @@ public void onConfigured(final ConfigurationContext 
config) throws Initializatio
             }
     
             final List<MemoryPoolMXBean> memoryPoolBeans = 
ManagementFactory.getMemoryPoolMXBeans();
    -        for (final MemoryPoolMXBean bean : memoryPoolBeans) {
    -            final String memoryPoolName = bean.getName();
    +        for (int i = 0; i < memoryPoolBeans.size() && monitoredBean == 
null; i++) {
    +            MemoryPoolMXBean memoryPoolBean = memoryPoolBeans.get(i);
    +            String memoryPoolName = memoryPoolBean.getName();
                 if (desiredMemoryPoolName.equals(memoryPoolName)) {
    -                monitoredBean = bean;
    -                if (DATA_SIZE_PATTERN.matcher(thresholdValue).matches()) {
    -                    final long bytes = 
DataUnit.parseDataSize(thresholdValue, DataUnit.B).longValue();
    -                    if (bean.isCollectionUsageThresholdSupported()) {
    -                        bean.setCollectionUsageThreshold(bytes);
    -                    }
    -                } else {
    -                    final String percentage = thresholdValue.substring(0, 
thresholdValue.length() - 1);
    -                    final double pct = Double.parseDouble(percentage) / 
100D;
    -                    final long calculatedThreshold = (long) 
(bean.getUsage().getMax() * pct);
    -                    if (bean.isCollectionUsageThresholdSupported()) {
    -                        
bean.setCollectionUsageThreshold(calculatedThreshold);
    +                monitoredBean = memoryPoolBean;
    +                if (memoryPoolBean.isCollectionUsageThresholdSupported()) {
    +                    long calculatedThreshold;
    +                    if 
(DATA_SIZE_PATTERN.matcher(thresholdValue).matches()) {
    +                        calculatedThreshold = 
DataUnit.parseDataSize(thresholdValue, DataUnit.B).longValue();
    +                    } else {
    +                        final String percentage = 
thresholdValue.substring(0, thresholdValue.length() - 1);
    +                        final double pct = Double.parseDouble(percentage) 
/ 100D;
    --- End diff --
    
    Can this ever throw a `NumberFormatException` or an 
`IndexOutOfBoundsException`? It looks like it's reading from a string that may 
be empty or have a unit abbreviation that is more than one character. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to