Railo > Lucee Component error: [java.lang.NullPointerException]

150 views
Skip to first unread message

Ivan

unread,
Dec 6, 2015, 5:11:27 AM12/6/15
to Lucee
Hello,
I want migrate from Railo (4.2.2.004) to Lucee (4.5.3.001) but I encountered a problem that I do not know to solve:



Using the component cfmailgun by Dominic Watson

With Railo working properly.
(sorry for my English)

Andrew Dixon

unread,
Dec 6, 2015, 5:35:09 AM12/6/15
to lu...@googlegroups.com
Hi Ivan,

I assume you have try to restart Lucee since upgrading? Also, 4.5.3.001 is only a bleeding edge release, the current stable release is 4.5.2.018, so not sure if this is a problem with the bleeding edge release, I would try the stable release.

Kind regards,

Andrew

--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/d2213d78-cc9f-4d1b-96c2-89abdf06e69b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ivan

unread,
Dec 6, 2015, 5:43:51 AM12/6/15
to Lucee
Hello Andrew,
I tried to remove the last patch and return to version 4.5.2.018. I also rebooted the server, but I have not solved.
In my opinion, I'm wrong. Not a problem of Lucee.

If you need any more information, I am here!

Jeroen Knoef

unread,
Dec 7, 2015, 5:17:26 AM12/7/15
to Lucee
Hi Ivan,

Not sure if this might be the cause, but the first argument of init() (apiKey) is required. I've never seen this message before though, so it's probably not the issue but who knows.

Kind regards,
Jeroen

Ivan

unread,
Dec 7, 2015, 5:25:35 AM12/7/15
to Lucee
Hi Jeroen,
apiKey is defined in the file MailGunClient.cfc (for my convenience)
Here you will find exactly the component as well as works on Railo: https://gist.github.com/ivanionut/71590e442114af05be8e

Jeroen Knoef

unread,
Dec 7, 2015, 5:33:33 AM12/7/15
to lu...@googlegroups.com
Ah ok.
 
As a test, you could just comment everything out in MailGunClient.cfc so that you're left with an empty component. Does it still throw? If yes: does the error go away if you don't call init? Can you create a completely different component on this spot without error?
If the error is gone at some point, you know where to drill down further. Hope this helps!

Ivan

unread,
Dec 7, 2015, 5:45:12 AM12/7/15
to Lucee
Hi,
I created the component MailGunClient.cfc:

<cfcomponent output="false">


<!--- CONSTRUCTOR --->
 
<cffunction name="init" access="public" returntype="any" output="false">
 
<cfscript>
 return this;
 
</cfscript>
 
</cffunction>


<!--- MESSAGES --->
 
<cffunction name="sendMessage" access="public" returntype="string" output="false">
 
<cfreturn true />
 
</cffunction>


</cfcomponent>



and called with:

<cfset Nnews = CreateObject( "component", "componenti.newsletter.com.MailGunClient" ).init() />
<cfoutput>#Nnews.sendMessage()#</cfoutput>


It works well.
Other components (in the same directory) work properly!



Ivan

unread,
Dec 8, 2015, 5:58:10 AM12/8/15
to Lucee
Hi,
I tried to create the component (MailGunClient.cfc) in another directory and the problem persists... It may be a bug or incompatibility of Lucee? Or is it a problem of the component?

How can I make a more thorough debugging?


Thank you all!

Jeroen Knoef

unread,
Dec 8, 2015, 7:21:53 AM12/8/15
to Lucee

Since the empty component can be instantiated, you could remove functions one at a time and see when the error goes away. Then you know there’s something in that function that Lucee chokes on. If you’ve found that function, comment out lines inside that function until there’s no error. That should give you the line where things go wrong. Could you post that line back here if you find it?

Ivan

unread,
Dec 8, 2015, 7:51:45 AM12/8/15
to Lucee

Hi,
I thought and thought… I think that the 99% that the problem lies in the following function:

<cffunction name="validate" access="public" returntype="boolean" output="false">
<cfargument name="address"     type="string" required="true" />


<cfscript>

_setApiKey( "pubkey-460ik78fbe8bu471dfsr9wtpf53gl4m6" );
var getVars = {};

if ( Len( Trim( arguments.address ) ) ) {
getVars.address = arguments.address;
};



var result = _restCall(
 httpMethod = "GET"
, uri        = "/address/validate"
, getVars    = getVars
);

if ( IsStruct( result ) and StructKeyExists( result, "is_valid" ) ) {
return structFind(result, "is_valid");
}

_throw(
 type      = "unexpected"
, message   = "Unexpected mailgun response. Expected a validate object (structure) but received  [#SerializeJson( result )#]"
, errorCode = 500
);
</cfscript>
</cffunction>



This function has been added by me to check if the email address is correct. But I repeat: on Railo worked...
Invoking the other functions, the component works.

What does not work in this function?

Ivan

unread,
Dec 8, 2015, 12:25:09 PM12/8/15
to Lucee
I correct what I wrote earlier... The problem seems to be in the "sendMessage". If I delete this function, the other functions seem to work...

<cffunction name="sendMessage" access="public" returntype="string" output="false" hint="Attempts to send a message through the MailGun API - returns message if successul and throws an error otherwise">
 
<cfargument name="from"              type="string"  required="true" />
 
<cfargument name="to"                type="string"  required="true" />
 
<cfargument name="subject"           type="string"  required="true" />
 
<cfargument name="text"              type="string"  required="true" />
 
<cfargument name="html"              type="string"  required="true" />
 
<cfargument name="cc"                type="string"  required="false" default="" />
 
<cfargument name="bcc"               type="string"  required="false" default="" />
 
<cfargument name="attachments"       type="array"   required="false" default="#ArrayNew(1)#" />
 
<cfargument name="inlineAttachments" type="array"   required="false" default="#ArrayNew(1)#" />
 
<cfargument name="domain"            type="string"  required="false" default="#_getDefaultDomain()#" />
 
<cfargument name="testMode"          type="boolean" required="false" default="false" />
 
<cfargument name="tags"              type="array"   required="false" default="#ArrayNew(1)#" />
 
<cfargument name="campaign"          type="string"  required="false" default="" />
 
<cfargument name="dkim"              type="string"  required="false" default="" />
 
<cfargument name="deliveryTime"      type="string"  required="false" default="" />
 
<cfargument name="tracking"          type="string"  required="false" default="" />
 
<cfargument name="clickTracking"     type="string"  required="false" default="" />
 
<cfargument name="openTracking"      type="string"  required="false" default="" />
 
<cfargument name="customHeaders"     type="struct"  required="false" default="#StructNew()#" />
 
<cfargument name="customVariables"   type="struct"  required="false" default="#StructNew()#" />


 
<cfscript>
 var result   = "";
 var files    = {};
 var postVars = {
  from    = arguments.from
 , to      = arguments.to
 , subject = arguments.subject
 , text    = arguments.text
 , html    = arguments.html
 };


 if ( Len( Trim( arguments.cc ) ) ) {
 postVars.cc = arguments.cc;
 }


 if ( Len( Trim( arguments.bcc ) ) ) {
 postVars.bcc = arguments.bcc;
 }


 if ( _getForceTestMode() or arguments.testMode ) {
 postVars[ "o:testmode" ] = "yes";
 }


 if ( ArrayLen( arguments.tags ) ) {
 postVars[ "o:tag" ] = arguments.tags;
 }


 if ( Len( Trim( arguments.campaign ) ) ) {
 postVars[ "o:campaign" ] = arguments.campaign;
 }


 if ( IsBoolean( arguments.dkim ) ) {
 postVars[ "o:dkim" ] = _boolFormat( arguments.dkim );
 }


 if ( IsDate( arguments.deliveryTime ) ) {
 postVars[ "o:deliverytime" ] = _dateFormat( arguments.deliveryTime );
 }


 if ( IsBoolean( arguments.tracking ) ) {
 postVars[ "o:tracking" ] = _boolFormat( arguments.tracking );
 }


 if ( IsBoolean( arguments.clickTracking ) ) {
 postVars[ "o:tracking-clicks" ] = _boolFormat( arguments.clickTracking );
 } elseif( arguments.clickTracking eq "htmlonly" ) {
 postVars[ "o:tracking-clicks" ] = "htmlonly";
 }


 if ( IsBoolean( arguments.openTracking ) ) {
 postVars[ "o:tracking-opens" ] = _boolFormat( arguments.openTracking );
 }


 for( var key in arguments.customHeaders ){
 postVars[ "h:X-#key#" ] = arguments.customHeaders[ key ];
 }


 for( var key in arguments.customVariables ){
 postVars[ "v:#key#" ] = arguments.customVariables[ key ];
 }


 if ( ArrayLen( arguments.attachments ) ) {
 files.attachment = arguments.attachments;
 }


 if ( ArrayLen( arguments.inlineAttachments ) ) {
 files.inline = arguments.inlineAttachments;
 }


 result = _restCall(
  httpMethod = "POST"
 , uri        = "/messages"
 , domain     = arguments.domain
 , postVars   = postVars
 , files      = files
 );


 if ( StructKeyExists( result, "id" ) ) {
 return result.id;
 }


 _throw(
  type    = "unexpected"
 , message = "Unexpected error processing mail send. Expected an ID of successfully sent mail but instead received [#SerializeJson( result )#]"
 );
 
</cfscript>
 
</cffunction>


Why do you think it does not work?

Jeroen Knoef

unread,
Dec 8, 2015, 1:55:59 PM12/8/15
to lu...@googlegroups.com
What happens if you remove all (most) arguments? This function has a lot of them, maybe lucee has some limit imposed on this? It's trial and error...
Other things you can try: rename the function, clear the function body. 

Verstuurd vanaf mijn iPhone
--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/6qfZ6Lk7ncc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lucee+un...@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.

Jon Clausen

unread,
Dec 8, 2015, 2:01:55 PM12/8/15
to lu...@googlegroups.com
I suspect it could be the "domain" argument.  Argument defaults need to be simple values or, if they call a function, that function needs to have a default static response, that doesn't depend on any variables set in the constructor.

[Note: Typo assistance courtesy of iPhone]
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.

Ivan

unread,
Dec 8, 2015, 2:14:38 PM12/8/15
to Lucee
OMG ... thanks to all I found the problem!

it's here:

if ( IsDate( arguments.deliveryTime ) ) {
 postVars
[ "o:deliverytime" ] = _dateFormat( arguments.deliveryTime );
}


Lucee not like the word "_dateFormat", so I changed and now it works! I will do more tests, but for now I can say I solved!

P.S. ye are a great community, ready to give advice to try to solve issues. Thank you!

Dominic Watson

unread,
Dec 12, 2015, 3:45:11 AM12/12/15
to Lucee
Sorry for the late reply, have just seen this. Nice find! Would you mind making a pull request with your fix?

Dominic :)
Reply all
Reply to author
Forward
0 new messages