{"record":{"id":"59312e7182313d5e","repo":"stanfordnlp/CoreNLP","slug":"attempt-to-use-externalfinitedifference-without-pa","errorCode":null,"errorMessage":"Attempt to use ExternalFiniteDifference without passing currentDerivative","messagePattern":"Attempt to use ExternalFiniteDifference without passing currentDerivative","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/optimization/AbstractStochasticCachingDiffFunction.java","lineNumber":495,"sourceCode":"  }\n\n  /**\n   *\n   * HdotVAt  will return the hessian vector product H.v at the point x for a batchSize subset of the data\n   *\n   * There are several ways to perform this calculation, as of now Finite Difference, and Algorithmic Differentiation\n   *  are the methods that have been used.  To use this function calculateStochastic must also fill the array\n   *  Hv with the hessian vector product.\n   *\n   * Alternative:  use the function getHdotVFiniteDifference which will simply make two calls to the function and\n   *    come up with an approximation to this value.\n   *\n   */\n\n  public double[] HdotVAt(double[] x, double[] v, int batchSize){\n\n    if (method == StochasticCalculateMethods.ExternalFiniteDifference){\n      throw new RuntimeException(\"Attempt to use ExternalFiniteDifference without passing currentDerivative\");\n      /*\n      if( extFiniteDiffDerivative == null )\n        extFiniteDiffDerivative = new double[x.length];\n\n      System.arraycopy(derivativeAt(x,x,batchSize),0,extFiniteDiffDerivative,0,extFiniteDiffDerivative.length);\n      getHdotVFiniteDifference(x,v,extFiniteDiffDerivative,batchSize);\n      */\n\n    } else {\n      //Call the objective Function\n      stochasticEnsure(x,v,batchSize);\n    }\n    return HdotV;\n  }\n\n\n  public double[] HdotVAt(double[] x, double[] v, double[] curDerivative, int batchSize){\n    if (method == StochasticCalculateMethods.ExternalFiniteDifference){","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/optimization/AbstractStochasticCachingDiffFunction.java#L477-L513","documentation":"AbstractStochasticCachingDiffFunction.HdotVAt computes the product of the Hessian approximation and a vector. For the ExternalFiniteDifference calculation method, this overload without a currentDerivative argument cannot operate (the finite-difference variant needs the current derivative), so it throws this RuntimeException unconditionally.","triggerScenarios":"Calling HdotVAt(x, v, batchSize) while method == StochasticCalculateMethods.ExternalFiniteDifference; typically from stochastic Hessian-vector or test code configured for external finite differences.","commonSituations":"Switching the stochastic calculate method to ExternalFiniteDifference without switching to the HdotVAt overload that accepts a derivative vector; copy-pasted optimizer setup from examples using a different method.","solutions":["Use the HdotVAt overload that takes currentDerivative, e.g. HdotVAt(x, v, batchSize, derivative)","Change the calculation method away from ExternalFiniteDifference (e.g. InlineFiniteDifference) before calling this overload","Compute the derivative first via derivativeAt(x, v, batchSize) and use the finite-difference helper directly"],"exampleFix":"// before\ndouble[] hv = f.HdotVAt(x, v, 100); // method is ExternalFiniteDifference\n// after\ndouble[] hv = f.HdotVAt(x, v, 100, f.derivativeAt(x, v, 100));","handlingStrategy":"validation","validationCode":"if (func.getMethod() == StochasticCalculateMethods.ExternalFiniteDifference)\n  hv = func.HdotVAt(x, v, batchSize, currentDerivative);\nelse\n  hv = func.HdotVAt(x, v, batchSize);","typeGuard":null,"tryCatchPattern":"try { hv = func.HdotVAt(x, v, batchSize); } catch (RuntimeException e) { if (e.getMessage().contains(\"ExternalFiniteDifference\")) { hv = func.HdotVAt(x, v, batchSize, func.derivativeAt(x, v, batchSize)); } else throw e; }","preventionTips":["Pair the HdotVAt overload with the configured StochasticCalculateMethods value","Write a small wrapper that hides the method-dependent dispatch","Keep the calculate method and Hessian-vector call sites in sync in one config place"],"tags":["java","stanford-nlp","optimization","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}