#vulnerable code 
                                public Template extend(String name, Locale locale, String encoding) throws IOException, ParseException {
    	if (name == null || name.length() == 0) {
            throw new IllegalArgumentException("include template name == null");
        }
        String macro = null;
		int i = name.indexOf('#');
        if (i > 0) {
        	macro = name.substring(i + 1);
        	name = name.substring(0, i);
        }
    	Template template = Context.getContext().getTemplate();
        if (template != null) {
	        if (encoding == null || encoding.length() == 0) {
	            encoding = template.getEncoding();
	        }
	        name = UrlUtils.relativeUrl(name, template.getName());
	        if (locale == null) {
	        	locale = template.getLocale();
	        }
        }
        Template extend = engine.getTemplate(name);
        if (macro != null && macro.length() > 0) {
        	extend = extend.getMacros().get(macro);
		}
        if (template != null && template == extend) {
        	throw new IllegalStateException("The template " + template.getName() + " can not be recursive extending the self template.");
        }
        Context.getContext().putAll(template.getMacros());
        return extend;
    } 
                            #location 28 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                                public Template extend(String name, Locale locale, String encoding) throws IOException, ParseException {
    	if (name == null || name.length() == 0) {
            throw new IllegalArgumentException("include template name == null");
        }
        String macro = null;
		int i = name.indexOf('#');
        if (i > 0) {
        	macro = name.substring(i + 1);
        	name = name.substring(0, i);
        }
    	Template template = Context.getContext().getTemplate();
        if (template != null) {
	        if (encoding == null || encoding.length() == 0) {
	            encoding = template.getEncoding();
	        }
	        name = UrlUtils.relativeUrl(name, template.getName());
	        if (locale == null) {
	        	locale = template.getLocale();
	        }
        }
        Template extend = engine.getTemplate(name);
        if (macro != null && macro.length() > 0) {
        	extend = extend.getMacros().get(macro);
		}
        if (template != null) {
        	if (template == extend) {
            	throw new IllegalStateException("The template " + template.getName() + " can not be recursive extending the self template.");
            }
            Context.getContext().putAll(template.getMacros());
        }
        return extend;
    }