Repository: GoogleContainerTools/jib
File: jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/JibPluginConfiguration.java (Java)

Code before:
  }

  /** Configuration for {@code platform} parameter. */
  public static class PlatformParameters implements PlatformConfiguration {

    @Nullable @Parameter private String os;
    @Nullable @Parameter private String architecture;

    @Override
    public Optional<String> getOsName() {
      return Optional.ofNullable(os);
    }

    @Override
    public Optional<String> getArchitectureName() {
      return Optional.ofNullable(architecture);
    }

    private static PlatformParameters ofString(String osArchitecture) {
      if (osArchitecture == null || !osArchitecture.matches("[^/]+/[^/]+")) {
        throw new IllegalArgumentException("osArchitecture must be of form os/architecture");
      }
      PlatformParameters platformParameters = new PlatformParameters();
      platformParameters.os = osArchitecture.split("/")[0].trim();
      platformParameters.architecture = osArchitecture.split("/")[1].trim();
      return platformParameters;
    }
  }

  /** Configuration for {@code from} parameter. */
  public static class FromConfiguration {

    @Nullable @Parameter private String image;
    @Nullable @Parameter private String credHelper;
    @Parameter private FromAuthConfiguration auth = new FromAuthConfiguration();
    @Parameter private List<PlatformParameters> platforms;

    /** Constructor for defaults. */
    public FromConfiguration() {
      platforms = Collections.singletonList(PlatformParameters.ofString("linux/amd64"));
    }
  }

  /** Configuration for {@code to} parameter, where image is required. */
  public static class ToConfiguration {

    @Nullable @Parameter private String image;
    @Parameter private List<String> tags = Collections.emptyList();
    @Nullable @Parameter private String credHelper;
    @Parameter private ToAuthConfiguration auth = new ToAuthConfiguration();


Review comment (refactor):
We use NullAway. The null check is unnecessary. And I don't like allowing whitespace and using `.trim()`. Let's just say `[^/ ]+/[^/ ]+`. And then, I think we can make this simpler:

```java
      Matcher matcher = Pattern.compile("([^/ ]+)/([^/ ]+)").matcher(osArchitecture);
      if (!matcher.matches()) {
        throw ...
      }
      PlatformParameters platformParameters = new PlatformParameters();
      platformParameters.os = matcher.group(1);
      platformParameters.architecture = matcher.group(2);
      return platformParameters;
```

And let's move this method to the top of the class (sorry, our repo style):
```java

public static class PlatformParameters implements PlatformConfiguration {

  private static PlatformParameters ofString(String osArchitecture) { ...
```

Code after:
    }
  }

  /** Configuration for {@code platform} parameter. */
  public static class PlatformParameters implements PlatformConfiguration {

    private static PlatformParameters of(String osArchitecture) {
      Matcher matcher = Pattern.compile("([^/ ]+)/([^/ ]+)").matcher(osArchitecture);
      if (!matcher.matches()) {
        throw new IllegalArgumentException("Platform must be of form os/architecture.");
      }
      PlatformParameters platformParameters = new PlatformParameters();
      platformParameters.os = matcher.group(1);
      platformParameters.architecture = matcher.group(2);
      return platformParameters;
    }

    @Nullable @Parameter private String os;
    @Nullable @Parameter private String architecture;

    @Override
    public Optional<String> getOsName() {
      return Optional.ofNullable(os);
    }

    @Override
    public Optional<String> getArchitectureName() {
      return Optional.ofNullable(architecture);
    }
  }

  /** Configuration for {@code from} parameter. */
  public static class FromConfiguration {

    @Nullable @Parameter private String image;
    @Nullable @Parameter private String credHelper;
    @Parameter private FromAuthConfiguration auth = new FromAuthConfiguration();
    @Parameter private List<PlatformParameters> platforms;

    /** Constructor for defaults. */
    public FromConfiguration() {
      platforms = Collections.singletonList(PlatformParameters.of("linux/amd64"));
    }
  }

  /** Configuration for {@code to} parameter, where image is required. */
  public static class ToConfiguration {

    @Nullable @Parameter private String image;
    @Parameter private List<String> tags = Collections.emptyList();
    @Nullable @Parameter private String credHelper;