Skip to content

Commit

Permalink
Fix NullPointerException and improve console error output (fixes #159)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwharm committed Dec 7, 2024
1 parent b29a64c commit f34e381
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions generator/src/main/java/io/github/jwharm/javagi/JavaGI.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
Expand Down Expand Up @@ -134,8 +131,12 @@ public static void main(String[] args) {
private static int handleException(Exception ex,
CommandLine cmd,
CommandLine.ParseResult parseResult) {
String message = Objects.requireNonNullElse(
ex.getMessage(),
ex.getClass().getSimpleName());

// bold red error message
cmd.getErr().println(cmd.getColorScheme().errorText(ex.getMessage()));
cmd.getErr().println(cmd.getColorScheme().errorText(message));

return cmd.getExitCodeExceptionMapper() != null
? cmd.getExitCodeExceptionMapper().getExitCode(ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;

import static io.github.jwharm.javagi.util.CollectionUtils.listOfNonNull;
import static java.util.Collections.emptyList;

public class GLibPatch implements Patch {
Expand Down Expand Up @@ -123,7 +124,7 @@ public GirElement patch(GirElement element, String namespace) {
*/
if (element instanceof Alias a && "Strv".equals(a.name())) {
return new Alias(a.attributes(),
List.of(a.infoElements().doc(),
listOfNonNull(a.infoElements().doc(),
a.infoElements().sourcePosition(),
new Array(Map.of("zero-terminated", "1"),
List.of(new Type(Map.of("name", "utf8"),
Expand Down

0 comments on commit f34e381

Please sign in to comment.