Lucee not calling the doFinally method inside custom tag


#1

I am trying to implement a custom tag in Java that extends lucee.runtime.ext.tag.BodyTagTryCatchFinallyImpl and needs to make use of javax.servlet.jsp.tagext.TryCatchFinally The problem is that during extension development the doFinally method is being called properly but when it is deployed as an extension I get the error below image

I am not sure if the “V” is supposed to be there and if that is causing the error or not. I have tried to copy a core Lucee tag line for line into my extension and just rename the tag but I get the same result. If I comment out the line <handle-exception>true</handle-exception> inside of my tag.tldx file then I don’t get the error but it doesn’t attempt to execute the doFinally method. It appears that in the Lucee source code this line must be set to true for it to call the doFinally method.

Is there something obvious that I am doing wrong? I don’t see any other Lucee extension that makes use of the doFinally method only the core Lucee tags.

@isapir @micstriit


#2

Here is the relevant code. Just some background I am trying to make a drop-in replacement extension for cflock that does distributed locking in cases where there is a clustered environment that is using a round robin method of distributing requests rather than sticky sessions. I already know there is a CFML version of what I am doing but I wanted to do this as more of a learning experience.

package com.squidfoundry.cluster.tag;

import lucee.commons.lang.StringUtil;
import lucee.runtime.exp.ApplicationException;
import lucee.runtime.exp.PageException;


public final class ClusterLock extends lucee.runtime.ext.tag.BodyTagTryCatchFinallyImpl {

	private String result = "cfclusterlock";

	@Override
	public void release() {
		super.release();
		System.out.println("RELEASING");
	}

	public void setType(String type) throws ApplicationException {
		System.out.println("Type is: " + type);
	}

	public void setThrowontimeout(boolean throwontimeout) {
		System.out.println("Throw on timeout is: " + throwontimeout);
	}

	public void setScope(String scope) throws ApplicationException {
		System.out.println("Scope is: " + scope);
	}

	public void setName(String name) throws ApplicationException {
		System.out.println("Name is: " + name);
	}

	public void setTimeout(Object oTimeout) throws PageException {
		System.out.println("Object Timeout is: " + oTimeout);
	}
	
	public void setTimeout(double timeout) {
		System.out.println("Timeout is: " + timeout);
	}

	public void setId(String id) {
		System.out.println("ID is: " + id);
	}

	public void setResult(String result) throws ApplicationException {
		if (StringUtil.isEmpty(result))
			return;
		this.result = result.trim();
	}

	@Override
	public int doStartTag() {
		try {	
	        System.out.println("Locking");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;
	}
			
	@Override
	public void doCatch(Throwable t) throws Throwable {
		t.printStackTrace();
		System.out.println("DOING CATCH");
	}
	
	@Override
	public void doFinally() {
		System.out.println("FINALLY YEA!!!!!");
	}
}
<!DOCTYPE taglib PUBLIC "-//Railo//DTD CFML Tag Library 1.0//EN"
	"dtd/web-cfmtaglibrary_1_0.dtd">
<taglib>
	<tlib-version>1.0</tlib-version>
	<cfml-version>1.0</cfml-version>
	<short-name>cluster-lock</short-name>
	<display-name>ClusterLock</display-name>
	<description>
		Drop in replacement for distributed locking in Lucee
	</description>
	<name-space>cf</name-space>
	<name-space-separator></name-space-separator>
	<el>
		<el-class>lucee.transformer.cfml.expression.CFMLExprTransformer</el-class>
	</el>
	
	<tag>
		<name>clusterlock</name>
		<tag-class bundle-name="{bundle-name}" bundle-version="{bundle-version}">com.squidfoundry.cluster.tag.ClusterLock</tag-class>
		<tte-class>lucee.transformer.cfml.evaluator.impl.Lock</tte-class>
		<allow-removing-literal>yes</allow-removing-literal>
		<body-content>must</body-content>
		<body-rtexprvalue>false</body-rtexprvalue>
		<handle-exception>true</handle-exception>
		<script>
			<type>multiple</type>
			<rtexprvalue>true</rtexprvalue>
		</script>
		<description>Locks Stuff</description>
		<attribute-type>fixed</attribute-type>
		<attribute>
			<type>object</type>
			<name>timeout</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
			<description></description>
		</attribute>
		<attribute>
			<type>string</type>
			<name>scope</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
			<description></description>
		</attribute>
		<attribute>
			<type>string</type>
			<name>name</name>
			<alias>id</alias>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
			<description></description>
		</attribute>
		<attribute>
			<type>boolean</type>
			<name>throwOnTimeout</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
			<description></description>
		</attribute>
		<attribute>
			<type>string</type>
			<name>type</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
			<description></description>
		</attribute>
		<attribute>
			<type>string</type>
			<name>result</name>
			<alias>variable,variablename</alias>
			<required>false</required>
			<default>cfclusterlock</default>
			<rtexprvalue>true</rtexprvalue>
			<description></description>
		</attribute>
	</tag>
</taglib>

#3

I believe the reason it isn’t working is because bundles get handled differently according to the source code and this ticket https://luceeserver.atlassian.net/browse/LDEV-602 I believe that it might not be an issue with my code and it is just something that has to be tweaked in the TagHelper file.


#4

I’m not sure about the exception you get (i did not check), but you cannot make an extension referencing classes from the core.
Extensions only can “see” the loader (lucee.jar). classes in core can change at any time without warning, only the classes/interfaces from the loader are stable.
so take this as an example


#5

@micstriit I will reply on the open ticket I made so all communication is in one place. https://luceeserver.atlassian.net/browse/LDEV-1911