code: static Engine engine(Service service, String hostname) {
          final Engine engine;
          try {
              final Method m = Service.class.getDeclaredMethod("getContainer");
              engine = (Engine) m.invoke(service);
          } catch (Exception e) {
              throw new Error("failed to invoke Service.getContainer()", e);
          }
  
          if (engine != null) {
              return engine;
          }
  
          // Create a new engine.
          final Engine newEngine = new StandardEngine();
          newEngine.setName("Tomcat");
          newEngine.setDefaultHost(hostname);
          newEngine.setRealm(new NullRealm());
          service.setContainer(newEngine);
          return newEngine;
      }
docs: Returns the {@link Engine} of the specified Tomcat {@link Service}. If the {@link Service} has no
  {@link Engine} set, a new {@link Engine} will be created and set.
  
  <p>The return type of {@link Service#getContainer()} has been changed from {@link Container} to
  {@link Engine} since 8.5. Calling it directly will cause {@link NoSuchMethodError}.