code: private synchronized static void allowPatchRequestsIfNeeded() throws GeneralException {
          if (isPatchRequestAllowed) {
              // Don't do anything if we've run this method before. We're in a
              // synchronized block, so return ASAP.
              return;
          }
  
          try {
              // Ensure we can access the fields we need to set.
              Field methodsField = HttpURLConnection.class.getDeclaredField("methods");
              methodsField.setAccessible(true);
  
              Field modifiersField = Field.class.getDeclaredField("modifiers");
              modifiersField.setAccessible(true);
              modifiersField.setInt(methodsField, methodsField.getModifiers() & ~Modifier.FINAL);
  
              Object noInstanceBecauseStaticField = null;
  
              // Determine what methods should be allowed.
              String[] existingMethods = (String[]) methodsField.get(noInstanceBecauseStaticField);
              String[] allowedMethods = getAllowedMethods(existingMethods);
  
              // Override the actual field to allow PATCH.
              methodsField.set(noInstanceBecauseStaticField, allowedMethods);
  
              // Set flag so we only have to run this once.
              isPatchRequestAllowed = true;
          } catch (IllegalAccessException | NoSuchFieldException e) {
              throw new GeneralException(CAN_NOT_ALLOW_PATCH);
          }
      }
docs: By default, HttpURLConnection does not support PATCH requests. We can
  however work around this with reflection. Many thanks to okutane on
  StackOverflow: https://stackoverflow.com/a/46323891/3521243.