Buggy code:
public class TricubicSplineInterpolator implements TrivariateGridInterpolator { public TricubicSplineInterpolatingFunction interpolate ( final double [ ] xval , final double [ ] yval , final double [ ] zval , final double [ ] [ ] [ ] fval ) throws DimensionMismatchException , NoDataException , NonMonotonicSequenceException , NumberIsTooSmallException { if ( ( ( ( ( xval . length ) == 0 ) || ( ( yval . length ) == 0 ) ) || ( ( zval . length ) == 0 ) ) || ( ( fval . length ) == 0 ) ) { throw new NoDataException ( ) ; } if ( ( xval . length ) != ( fval . length ) ) { throw new DimensionMismatchException ( xval . length , fval . length ) ; } MathArrays . checkOrder ( xval ) ; MathArrays . checkOrder ( yval ) ; MathArrays . checkOrder ( zval ) ; final int xLen = xval . length ; final int yLen = yval . length ; final int zLen = zval . length ; final double [ ] [ ] [ ] fvalXY = new double [ zLen ] [ xLen ] [ yLen ] ; final double [ ] [ ] [ ] fvalZX = new double [ yLen ] [ zLen ] [ xLen ] ; for ( int i = 0 ; i < xLen ; i ++ ) { if ( ( fval [ i ] . length ) != yLen ) { throw new DimensionMismatchException ( fval [ i ] . length , yLen ) ; } for ( int j = 0 ; j < yLen ; j ++ ) { if ( ( fval [ i ] [ j ] . length ) != zLen ) { throw new DimensionMismatchException ( fval [ i ] [ j ] . length , zLen ) ; } for ( int k = 0 ; k < zLen ; k ++ ) { final double v = fval [ i ] [ j ] [ k ] ; fvalXY [ k ] [ i ] [ j ] = v ; fvalZX [ j ] [ k ] [ i ] = v ; } } } <START_BUG> final BicubicSplineInterpolator bsi = new BicubicSplineInterpolator ( ) ; <END_BUG> final BicubicSplineInterpolatingFunction [ ] xSplineYZ = new BicubicSplineInterpolatingFunction [ xLen ] ; for ( int i = 0 ; i < xLen ; i ++ ) { xSplineYZ [ i ] = bsi . interpolate ( yval , zval , fval [ i ] ) ; } final BicubicSplineInterpolatingFunction [ ] ySplineZX = new BicubicSplineInterpolatingFunction [ yLen ] ; for ( int j = 0 ; j < yLen ; j ++ ) { ySplineZX [ j ] = bsi . interpolate ( zval , xval , fvalZX [ j ] ) ; } final BicubicSplineInterpolatingFunction [ ] zSplineXY = new BicubicSplineInterpolatingFunction [ zLen ] ; for ( int k = 0 ; k < zLen ; k ++ ) { zSplineXY [ k ] = bsi . interpolate ( xval , yval , fvalXY [ k ] ) ; } final double [ ] [ ] [ ] dFdX = new double [ xLen ] [ yLen ] [ zLen ] ; final double [ ] [ ] [ ] dFdY = new double [ xLen ] [ yLen ] [ zLen ] ; final double [ ] [ ] [ ] d2FdXdY = new double [ xLen ] [ yLen ] [ zLen ] ; for ( int k = 0 ; k < zLen ; k ++ ) { final BicubicSplineInterpolatingFunction f = zSplineXY [ k ] ; for ( int i = 0 ; i < xLen ; i ++ ) { final double x = xval [ i ] ; for ( int j = 0 ; j < yLen ; j ++ ) { final double y = yval [ j ] ; dFdX [ i ] [ j ] [ k ] = f . partialDerivativeX ( x , y ) ; dFdY [ i ] [ j ] [ k ] = f . partialDerivativeY ( x , y ) ; d2FdXdY [ i ] [ j ] [ k ] = f . partialDerivativeXY ( x , y ) ; } } } final double [ ] [ ] [ ] dFdZ = new double [ xLen ] [ yLen ] [ zLen ] ; final double [ ] [ ] [ ] d2FdYdZ = new double [ xLen ] [ yLen ] [ zLen ] ; for ( int i = 0 ; i < xLen ; i ++ ) { final BicubicSplineInterpolatingFunction f = xSplineYZ [ i ] ; for ( int j = 0 ; j < yLen ; j ++ ) { final double y = yval [ j ] ; for ( int k = 0 ; k < zLen ; k ++ ) { final double z = zval [ k ] ; dFdZ [ i ] [ j ] [ k ] = f . partialDerivativeY ( y , z ) ; d2FdYdZ [ i ] [ j ] [ k ] = f . partialDerivativeXY ( y , z ) ; } } } final double [ ] [ ] [ ] d2FdZdX = new double [ xLen ] [ yLen ] [ zLen ] ; for ( int j = 0 ; j < yLen ; j ++ ) { final BicubicSplineInterpolatingFunction f = ySplineZX [ j ] ; for ( int k = 0 ; k < zLen ; k ++ ) { final double z = zval [ k ] ; for ( int i = 0 ; i < xLen ; i ++ ) { final double x = xval [ i ] ; d2FdZdX [ i ] [ j ] [ k ] = f . partialDerivativeXY ( z , x ) ; } }

Fix:
final BicubicSplineInterpolator bsi = new BicubicSplineInterpolator ( true ) ;