Class SerializeToByteArrayHack

java.lang.Object
com.diffplug.spotless.yaml.SerializeToByteArrayHack
All Implemented Interfaces:
FormatterStep, Serializable, AutoCloseable

public class SerializeToByteArrayHack extends Object implements FormatterStep
This step is a flag which marks that `ConfigurationCacheHackList` should serialize each item individually into `byte[]` array, rather than using normal serialization. The reason to use this is if you are using `toggleOffOn` *and* two kinds of google-java-format (e.g. one for format and the other for imports), then problems with Java's handling of object graphs will cause your up-to-date checks to always fail. `CombinedJavaFormatStepTest` recreates this situation. By adding this step, it will trigger this workaround which fixes the up-to-dateness bug. But, turning it on will break all `custom` steps that use Groovy closures. So by default you get regular serialization. If you're using `toggleOffOn` and having problems with up-to-dateness, then adding this step can be a workaround.
See Also:
  • Constructor Details

    • SerializeToByteArrayHack

      public SerializeToByteArrayHack()
  • Method Details

    • getName

      public String getName()
      Description copied from interface: FormatterStep
      The name of the step, for debugging purposes.
      Specified by:
      getName in interface FormatterStep
    • format

      @Nullable public String format(String rawUnix, File file) throws Exception
      Description copied from interface: FormatterStep
      Returns a formatted version of the given content.
      Specified by:
      format in interface FormatterStep
      Parameters:
      rawUnix - the content to format, guaranteed to have unix-style newlines ('\n'); never null
      file - the file which rawUnix was obtained from; never null. Pass the reference Formatter.NO_FILE_SENTINEL if and only if no file is actually associated with rawUnix
      Returns:
      the formatted content, guaranteed to only have unix-style newlines; may return null if the formatter step doesn't have any changes to make
      Throws:
      Exception - if the formatter step experiences a problem
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception