viktorthang / mgwt

Automatically exported from code.google.com/p/mgwt
Other
0 stars 0 forks source link

Carousel refresh nullpointer exception #331

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
This does not happen every time but quite often.
1. Add a carousel to a layoutPanel. 
2. Force a refresh. In my case rotate the device.
3. Remove the carousel
4. Force a refresh.
5. Add the carousel again.
6. Swipe the carousel

What is the expected output? What do you see instead?
NullPointerException Carousel.java line 317 funktion refresh():

 public void refresh() {

    IMPL.adjust(main, container);

    scrollPanel.setScrollingEnabledX(true);
    scrollPanel.setScrollingEnabledY(false);

    scrollPanel.setShowScrollBarX(false);
    scrollPanel.setShowScrollBarY(false);

    if (carouselIndicatorContainer != null) {
      carouselIndicatorContainer.removeFromParent();

    }

    int widgetCount = container.getWidgetCount();

    carouselIndicatorContainer = new CarouselIndicatorContainer(this.appearance.css(), widgetCount);

    if(isVisibleCarouselIndicator){
      main.add(carouselIndicatorContainer);
    }

    if (currentPage >= widgetCount) {
      currentPage = widgetCount - 1;
    }

    carouselIndicatorContainer.setSelectedIndex(currentPage);

    scrollPanel.refresh();

    refreshHandler = scrollPanel.addScrollRefreshHandler(new ScrollRefreshEvent.Handler() {

      @Override
      public void onScrollRefresh(ScrollRefreshEvent event) {
        refreshHandler.removeHandler(); <------------------------------- NPE
        refreshHandler = null;

        scrollPanel.scrollToPage(currentPage, 0, 0);

      }
    });

  }

What version of the product are you using? On what operating system?

Please provide any additional information below.
A simple refreshHandler != null check would fix this.

Original issue reported on code.google.com by c...@rahmstrom.com on 4 Jun 2014 at 12:03

GoogleCodeExporter commented 8 years ago
Are you seeing the same problem with mgwt 2.0-m2-alpha2?

Original comment by kurka.da...@gmail.com on 13 Jun 2014 at 9:43

GoogleCodeExporter commented 8 years ago
Yes. Both 1.2 and 2.0.

Original comment by c...@rahmstrom.com on 13 Jun 2014 at 9:45

GoogleCodeExporter commented 8 years ago
Can you post a simple reproducing example?

Original comment by kurka.da...@gmail.com on 5 Aug 2014 at 8:26

GoogleCodeExporter commented 8 years ago
Any simple example seems to work fine. I can only reproduce with our rather 
complex code. And it only happens occasionally. 

I suggest this simple fix:

refreshHandler = scrollPanel.addScrollRefreshHandler(new 
ScrollRefreshEvent.Handler() {

      @Override
      public void onScrollRefresh(ScrollRefreshEvent event) {
        if (refreshHandler != null) { <-------------------------------------- New null check
            refreshHandler.removeHandler(); <------------------------------- Avoids any NPE here
        }
        refreshHandler = null;

        scrollPanel.scrollToPage(currentPage, 0, 0);

      }
    });

Original comment by c...@schoolity.com on 5 Aug 2014 at 9:08

GoogleCodeExporter commented 8 years ago
Well if this order is broken for any reason there is obviously something fishy 
going on.

Can you post a more complex example that reproduces this?

btw: moving this to the new issue tracker: 
https://github.com/mgwt/mgwt/issues/122

Original comment by kurka.da...@gmail.com on 9 Aug 2014 at 9:08