@Override
    public GremlinScriptEngine getEngineByExtension(final String extension) {
        if (null == extension) throw new NullPointerException();
        //look for registered extension first
        Object obj;
        if (null != (obj = extensionAssociations.get(extension))) {
            final GremlinScriptEngineFactory spi = (GremlinScriptEngineFactory) obj;
            try {
                return createGremlinScriptEngine(spi);
            } catch (Exception exp) {
                logger.error(String.format("Could not create GremlinScriptEngine for %s", extension), exp);
            }
        }

        for (GremlinScriptEngineFactory spi : engineSpis) {
            List<String> exts = null;
            try {
                exts = spi.getExtensions();
            } catch (Exception exp) {
                logger.error("Could not get GremlinScriptEngine extensions", exp);
            }
            if (exts == null) continue;
            for (String ext : exts) {
                if (extension.equals(ext)) {
                    try {
                        return createGremlinScriptEngine(spi);
                    } catch (Exception exp) {
                        logger.error(String.format("Could not create GremlinScriptEngine for %s", extension), exp);
                    }
                }
            }
        }
        return null;
    }
Look up and create a {@link GremlinScriptEngine} for a given extension.  The algorithm
used by {@link #getEngineByName(String)} is used except that the search starts by looking for a
{@link GremlinScriptEngineFactory} registered to handle the given extension using
{@link #registerEngineExtension(String, GremlinScriptEngineFactory)}.

@return The engine to handle scripts with this extension.  Returns {@code null} if not found.
@throws NullPointerException if extension is {@code null}.
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultGremlinScriptEngineManager.java