1

In GXT 3.0, valueProvider, I have a null pointer exception issue. I have this code snippet,

@Path("xxx.yyy")
ValueProvider<User, String> zzz();

I use a ValueProvider like this, and in this situation, if xxx or yyy is null, I simply got null pointer exception. In my implementation, yyy or xxx could be null but, I want that, if it's null, simply just don't show it or show it empty.

I use this ValueProviders almost everywhere in my implementation, so I need to find a wise solution in order not to make my code sphagetti.

Thanks for any help.

Uğurcan Şengit
  • 976
  • 1
  • 11
  • 31
  • 1
    I think your problem is your path. GXT will create the following code from your annotation: getXxx().getYyy(). If getXxx() is null a NPE will occur, because GXT tries to get the value of getYyy(). – El Hoss Oct 08 '13 at 08:33
  • But when NPE occurs build failed. I want that if it's null, just let it be something like empty String. Let me keep on process I mean. – Uğurcan Şengit Oct 08 '13 at 12:48
  • You can add a fake getter `getzzz()` which returns exactly what you want. Then, your path will be `@Path("zzz")` – Arnaud Denoyelle Oct 10 '13 at 12:51

1 Answers1

2

I see 2 solutions :

  • You can add a fake getter getZzz() on your object and make it return exactly what you want to display:
  • You can give the implementation of the ValueProvider.

Example:

ValueProvider<User, String> zzz = new ValueProvider<User, String>() {

  @Override
  public String getValue(User user) {
    if(user.getXxx() == null | user.getXxx().getYyy() == null) {
      return "";
    }
    return object.getXxx().getYyy();
  }

  @Override
  public void setValue(User object, String value) {}

  @Override
  public String getPath() {
    return "xxx.yyy";
  }
}
Arnaud Denoyelle
  • 29,980
  • 16
  • 92
  • 148
  • 1
    Of course I could think this solution, but I needed wiser one, as I said in question, if I would use this implementation, my code would become sphagetti. I have nearly 90 path implementations like this. My supervisor has edited the Sencha's library and we get rid of the problem. Thanks for all. – Uğurcan Şengit Oct 10 '13 at 14:58