<commit_before>package org.mule.mvel2.optimizers.impl.refl.nodes;

import org.mule.mvel2.ParserContext;
import org.mule.mvel2.compiler.Accessor;
import org.mule.mvel2.compiler.AccessorNode;
import org.mule.mvel2.integration.VariableResolverFactory;
import org.mule.mvel2.optimizers.OptimizerFactory;

public class NullSafe implements AccessorNode {
  private AccessorNode nextNode;
  private char[] expr;
  private int start;
  private int offset;
  private ParserContext pCtx;
  private Accessor innerAccessor;

  public NullSafe(char[] expr, int start, int offset, ParserContext pCtx) {
    this.expr = expr;
    this.start = start;
    this.offset = offset;
    this.pCtx = pCtx;
  }

  public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) {
    if (ctx == null) return null;
    if(innerAccessor == null) {
      innerAccessor = OptimizerFactory.getAccessorCompiler(OptimizerFactory.SAFE_REFLECTIVE)
              .optimizeAccessor(pCtx, expr, start, offset, ctx, elCtx, variableFactory, true, ctx.getClass());
    }

    // This is intended to avoid an infinite recursion.
    // A null safe bean property should return null in
    // order to end the evaluation process when the
    // there is no key found.
    if (innerAccessor instanceof NullSafe) {
      return null;
    }

    if (nextNode != null) {
      return nextNode.getValue(ctx, elCtx, variableFactory);
    }
    else {
      return innerAccessor.getValue(ctx, elCtx, variableFactory);
    }
  }

  public Object setValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory, Object value) {
    if (ctx == null) return null;
    return nextNode.setValue(ctx, elCtx, variableFactory, value);
  }

  public AccessorNode getNextNode() {
    return nextNode;<commit_msg> MULE-16674: MEL caching null values after second nullsafe operation is done (#40)<commit_after>package org.mule.mvel2.optimizers.impl.refl.nodes;

import org.mule.mvel2.ParserContext;
import org.mule.mvel2.compiler.Accessor;
import org.mule.mvel2.compiler.AccessorNode;
import org.mule.mvel2.integration.VariableResolverFactory;
import org.mule.mvel2.optimizers.OptimizerFactory;

public class NullSafe implements AccessorNode {
  private AccessorNode nextNode;
  private char[] expr;
  private int start;
  private int offset;
  private ParserContext pCtx;
  private Accessor innerAccessor;

  public NullSafe(char[] expr, int start, int offset, ParserContext pCtx) {
    this.expr = expr;
    this.start = start;
    this.offset = offset;
    this.pCtx = pCtx;
  }

  public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) {
    if (ctx == null) return null;
    if(innerAccessor == null) {
      innerAccessor = OptimizerFactory.getAccessorCompiler(OptimizerFactory.SAFE_REFLECTIVE)
              .optimizeAccessor(pCtx, expr, start, offset, ctx, elCtx, variableFactory, true, ctx.getClass());
    }

    // This is intended to avoid an infinite recursion.
    // A null safe bean property should return null in
    // order to end the evaluation process when the
    // there is no key found.
    if (innerAccessor instanceof NullSafe) {
      innerAccessor = null;
      return null;
    }

    if (nextNode != null) {
      return nextNode.getValue(ctx, elCtx, variableFactory);
    }
    else {
      return innerAccessor.getValue(ctx, elCtx, variableFactory);
    }
  }

  public Object setValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory, Object value) {
    if (ctx == null) return null;
    return nextNode.setValue(ctx, elCtx, variableFactory, value);
  }

  public AccessorNode getNextNode() {
    return nextNode;
{'fraction_non_alphanumeric': 0.08843537414965986, 'fraction_numerical': 0.0051700680272108845, 'mean_word_length': 3.731016731016731, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6203656', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1085, 'n_words': 315}