Simple puzzle NPE (String)

We had training related to java, and was short example of code, like that :

and all developers tried to find places where NPE can be thrown. Yes, we found that name can be null

also that agent.getFullName() can throw NPE. But I asked, next question :

So, here is short description how that can be implemented 🙂

OK, we should know where method length() is declared, short investigation can show us that method length() is from interface CharSequence.

The answer we cannot! (Reflection we cannot use for that task)

OK, So, we have full information and can start develop our puzzle with throwing NPE in length() method.

First step is develop String and StringUtils.


and  Second is just a main method with calling util class.

READ  Drupal:: How to Add User Pictures

SO, this is simple trick 🙂 to get NPE in length() method 🙂

What is the advice, try to think out of the scope 🙂

Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *