Stackoverflow: Recursive call in namepatternFilter

I’m new to eclipse development and I’m working on a custom namepatternfilter for Jface tree viewer. I have the below code in my filter which recursively goes through children of a node element.

public boolean isChildMatch(final Object element) {
    boolean value = false;

    // Object[] children = this.contentProvider.getChildren(element);
    Object[] items = null;
    if (((HashMap<Object, String>) getTreeMap().get(element)) == null) {
      final Object[] children = this.contentProvider.getChildren(element);
      items = children;
      new Thread(new Runnable() {

        @Override
        public void run() {
          final HashMap<Object, String> childrenMap = new HashMap<Object, String>();
          for (Object object : children) {
            childrenMap.put(object, null);
          }
          NamePatternFilter.this.getTreeMap().put(element, childrenMap);
        }
      }).start();
    }
    else {
      items = ((HashMap<Object, String>) getTreeMap().get(element)).keySet().toArray();
    }
    for (Object child : items) {
      if (isElementMatch(child)) {
        value = true;
        break;
      }
      else if (isChildMatch(child)) {
        this.visibleElements.add(child);
        value = true;
        break;
      }
    }

    return value;

  }

When i run the code, I’m getting stackoverflow exception

org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.StackOverflowError)
    at org.eclipse.swt.SWT.error(SWT.java:4441)
    at org.eclipse.swt.SWT.error(SWT.java:4356)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:139)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4147)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3764)

What am I missing here?


Source: eclipse

Leave a Reply