2009-10-17

Java Proxy instance throws a NullPointerException

This is something I just found out, and I figured I'd blog about it for those that might come across this in the future.

I'm writing some code in a project (JZBot specifically, http://jzbot.googlecode.com) that uses java.lang.reflect.Proxy. At one point, I was calling a method on a proxy instance, and it was throwing a NullPointerException. The weird thing about this was that the NullPointerException was being thrown from within the proxy instance itself, not from the InvocationHandler that it is supposed to call. Other methods on the proxy worked, indicating that there wasn't some error with the invocation handler somehow being set to null.

Eventually, I found the problem: I had declared the method on the interface that the proxy implemented to return a boolean, but the invocation handler was returning null. The auto-unboxing that was being done by the proxy instance internally was messing things up. I changed the method's return type to void (which is what it should have been), and everything worked.

This is yet another example of where to watch out for autoboxing and unboxing. Admittedly, it would be more helpful if the NPE had a message stating something like, for example, "null can't be unboxed to a boolean", which would most likely have saved me quite a bit of time. Oh well.

25 comments:

Ran said...

Thanks for this, I found it very helpful! (In my case, the method was hashCode, so the conversion was from Integer to int rather than Boolean to boolean, but, same idea.)

Vince said...

Thanks for posting this!

Unknown said...

Thanks for posting this! I had the same problem and was wondering and wondering... ;-)

siiilon said...

Thank you :)

Unknown said...

Thanks for posting this blog entry. I had a similar problem that I was banging my head against. I couldn't change the method signature to void, in my case, but returning a proper default value (0 or false) instead of null fixed the problem.

Rathinam said...

Thank you for your sharing and I want to more updates for my research..
Appium Training in Chennai
Appium Certification in Chennai
Pega Training in Chennai
Tableau Training in Chennai
Advanced Excel Training in Chennai
Spark Training in Chennai
Primavera Training in Chennai
Unix Training in Chennai
Power BI Training in Chennai
Corporate Training in Chennai
Placement Training in Chennai

Sophia Lucas said...

Good post. I learn something totally new and challenging on blog IS stumble upon everyday. It’s always helpful to read through articles from other authors and use a little something from their sites. Turkey tourism.You can check all Turkey tourism Guidelines Turkey through Turkey e-Visa website.

Ava said...

This is a very useful article… India etv visa fee depends on your visa type and your nationality

James said...

I appreciate your work... Thanks for sharing... There is good news for international travelers. The Indian government restored the Indian tourism sector and also India tourist visa for the long term, which means I have more time to explore India.

Lillian said...

Hii friends, I wanted to write a little Info related to Visa. Are you interested in traveling to any country? Yes, you can apply for a visa online. You can fill out your visa application form online within 5 to 10 minutes via our Visacent website. We offer visas to citizens of over 190 countries. You can read more info about visas via our website.

alex said...

"The quality of your writing and the logical flow of your ideas are remarkable. This post is a fantastic resource, and your passion for the subject shines through." Do you know  Egypt Introduces New Residency Fees, now need to furnish proof of converting all relevant fees from U.S. dollars or their equivalent foreign currencies into Egyptian pounds, as per the new regulation.

mathewsmith said...

Your writing is truly remarkable! This paragraph is a shining example of your talent, and I'm eagerly looking forward to more posts of this caliber. Stay informed with the most recent Japan vaccine guidelines.Japan had introduced strict vaccine requirements for travelers.

alex said...

Your blog entry resonated deeply with my own experiences, highlighting the depth of human connections and the meaningful impact of simple acts of kindness."This is information I believe is worth sharing."
"Turkey entry requirements vary by nationality. It's essential to research and comply with the specific visa and documentation regulations before traveling. Adhering to Turkey's entry requirements ensures a smooth and enjoyable visit to this beautiful country."

steve said...

You're knocking it out of the park with your reporting, and I'm continually amazed by your professionalism and expertise. Keep up the excellent work, and know that I'm here to support you.
The India tourist visa fee for USA citizens varies depending on the duration of the visa and the type of entry required. As of the latest information available, the fee structure typically includes different tiers for various visa durations, such as 10 years, 5 years, or shorter stays.

Phineas said...

Your insights are valuable and easy to understand, making complex subjects clear and engaging. It feels like learning from a knowledgeable friend. I'm saving your content for future reference and can't wait for more great work! Apply for your Cameroon visa application easily with quick access to the application form. Complete it, attach the necessary documents, and submit. The simple interface and clear instructions make the process smooth, helping you get ready for your trip to Cameroon quickly and efficiently.

Alexender said...

Discovering this post feels like stumbling upon a treasure trove of wisdom amidst the vast digital sea! Your knack for simplifying complex concepts is truly admirable. Reading through, I felt like I was embarking on a journey of enlightenment. Planning a trip to Saudi Arabia and wondering about How much is Saudi tourist visa for US citizens? You're not alone! As of the latest updates, the Saudi tourist visa fee for US citizens varies depending on the duration of stay. And regarding more Information visit Our website.

Nikkitr Godman said...

The thorough analysis and the straightforwardness with which you explained complicated concepts were impressive. I particularly appreciated the real-world examples that brought a practical aspect to the discussion. Your writing is both engaging and informative, capturing my attention from beginning to end. How long does it take to get an Ethiopian e-Visa from Israel? The processing time for an Ethiopian e-Visa from Israel typically ranges from one to three business days. Applicants need to complete an online form, submit a valid passport, a recent passport-sized photo, and pay the visa fee. Once approved, the e-Visa is electronically issued and sent via email. Ensure your passport is valid for at least six months beyond your intended date of entry into Ethiopia.

davidjons said...

I’m thoroughly impressed by this blog! You’ve explained the topic so clearly, providing practical examples that make it easy to relate to and apply. Your engaging writing style keeps the reader invested, while the depth of research ensures every point is credible. Tanzania e visa online application Applying for a Tanzania e-Visa online is a simple and convenient process. Travelers can complete the application form online  ents such as a passport and photograph, and pay the visa fee using a secure payment method. Once submitted, the e-Visa is typically processed within a few days, and the approved document is sent via email. This digital visa allows entry for tourism, business, or transit purposes.

Nikkitr Godman said...

You have a talent for explaining things in a way that feels personal yet professional. The examples and anecdotes sprinkled throughout the post brought the content to life. I found myself nodding along with each point you made. It’s rare to come across content that feels both educational and entertaining, but you’ve nailed it here. Thank you for sharing your expertise and making this such a valuable resource. If you're a US citizen planning a visit to Azerbaijan, understanding the visa requirements for US citizens to Azerbaijan is crucial. The country provides a straightforward e-visa system, allowing travelers to apply online with ease. US citizens must submit an application and provide required documents, such as a passport with sufficient validity. The application process is relatively simple and ensures that visitors can easily obtain permission to enter. Knowing these requirements ahead of time will help you plan your trip effectively and avoid any last-minute surprises.

Micheal said...

This is an exceptional post! Your writing feels genuine, and the insights you’ve shared resonate deeply. I love how you’ve blended personal stories with practical advice—it makes the content so much more relatable. When planning a trip to Laos, understanding the visa requirements to enter Laos is essential for a smooth journey. Depending on your nationality, you may need to apply for a visa beforehand or get one on arrival. Always check the latest regulations, as requirements can vary and impact your travel plans significantly. Preparation ensures a hassle-free experience.

carry john said...

Fantastic post! The advice you gave is both insightful and practical. I love how you break down tough concepts into easy-to-follow tips. Your engaging writing style made the entire article enjoyable. Looking forward to more posts like this. Keep up the excellent work, and thank you for sharing! Myanmar visa application form is the first step in obtaining your Myanmar eVisa. This user-friendly online form simplifies the application process, allowing you to easily fill in your details and upload the necessary documents. The Myanmar eVisa application form is designed for convenience, ensuring a smooth and efficient process. With quick processing times, you can focus on preparing for your trip to explore Myanmar’s unique culture and stunning landscapes. Apply now and start your adventure!

alex said...

Another standout feature of the post was the way the author acknowledged different perspectives. The post didn’t feel one-sided or overly biased. Instead, it presented a variety of viewpoints, which allowed me to see the broader context of the discussion. To apply Benin e-visa application, travelers can complete the necessary forms and submit required documents electronically. This online process simplifies the visa application experience, saving time and effort. When you apply Benin e visa application, it is crucial to provide accurate information and meet all specified requirements to avoid any delays.

Martin Lewis said...

This is precisely the kind of content that captivates my attention and keeps me engaged every time! The thoughtfulness shines through in every word, drawing me into its compelling narrative. It’s presented with such care and intentionality that it feels like a conversation crafted just for the reader. I find myself savoring each point, appreciating the depth and clarity that elevate the entire experience. South African travelers can easily apply for an e visa for Turkey from south Africa, simplifying the entry process. The e visa allows for quick and hassle-free access to Turkey, eliminating the need for a traditional visa application. The process is straightforward, requiring basic information and a few supporting documents. Once approved, the e visa for Turkey is sent electronically, making it a convenient choice for those looking to explore Turkey’s rich culture, history, and vibrant landscapes without delays.

john merry said...
This comment has been removed by the author.
john merry said...

I find your writing style to be incredibly engaging and informative. Your posts are always anticipated with great excitement, as they provide valuable insights and an enjoyable reading experience. Curious about How to apply Russia evisa It’s a quick and easy procedure. Just fill out the application form, and upload your documents. The Russia eVisa allows travelers to discover the country's stunning architecture, museums, and cultural sites. This simple online visa is a convenient option for anyone looking to visit Russia without the complexity of traditional visa applications. Don't miss out on the opportunity to experience this incredible destination.