question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ghProjectCard.content.repository is null

See original GitHub issue

Describe the bug A clear and concise description of what the bug is.

Try to call getRepository on an issue instantiated from a getContent call on a GHProjectCard throws an NPE.

val gitHub = GitHubBuilder.fromPropertyFile().build()
println(gitHub.myself)
val project = gitHub.getOrganization(organization).listProjects().single { it.number == projectNumber }
val issues = project.listColumns().flatMap { ghProjectColumn ->
    println("Scanning column: ${ghProjectColumn.name}")
    ghProjectColumn.listCards().mapNotNull { ghProjectCard ->
        ghProjectCard.content?.run {
            SecurityBoardIssue(
                title = title,
                dateCreated = createdAt,
                column = ghProjectColumn.name,
                repository = repository.name // throws NPE
            )
        }
    }
}

Expected behavior

Should be able to determine the repository that a project card originates from.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bitwisemancommented, Sep 16, 2021

It is still there. root streamlining did not fix this. @JLLeitschuh Great analysis. Thanks.

0reactions
bitwisemancommented, Sep 26, 2021

@JLLeitschuh Here’s the getContent() method: https://github.com/hub4j/github-api/blob/2dc736ab2135bc200903f4bae887ac137c9cfc13/src/main/java/org/kohsuke/github/GHProjectCard.java#L124-L136

GHPullRequest extends GHIssue so the we only need to change GHIssue.getRepository(). https://github.com/hub4j/github-api/blob/2dc736ab2135bc200903f4bae887ac137c9cfc13/src/main/java/org/kohsuke/github/GHIssue.java#L87-L90

Add a null check. If null, get the URL for this item this.getUrl(), truncate it to get the repository url, and retrieve the repository using that url. Does that make sense?

Rough example:

public GHRepository getRepository() {
    if (owner == null) {
        String repositoryUrlPath = getRepositoryUrlPath();
        owner = root().createRequest().withUrlPath(repositoryUrlPath).fetch(GHRepository.class);
    }
    return owner;
}

private String getRepositoryUrlPath() {
    String url = getUrl().toString();
    int index = url.indexOf("/issues");
    if (index == -1) {
        index = url.indexOf("/pulls");
    } 
    return url.substring(0, index);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

github-api - Bountysource
gitHub.getRepository(ghContent.getOwner().getFullName()).getStargazersCount()); returns the proper count. Probably related to #349 and #1068. Expected behavior
Read more >
java - spring boot Cannot invoke Repository because ...
You are trying to inject the field customerRepository using Autowired annotation, but your class is not injectable.
Read more >
1. Working with Spring Data Repositories
The CrudRepository provides sophisticated CRUD functionality for the entity class that is being managed. Example 1.1. CrudRepository interface. public interface ...
Read more >
Oracle ATG Web Commerce - IS NULL
An IS NULL query can determine whether an expression evaluates to null. For example: phoneNumber IS NULL ... SQL Repository Architecture.
Read more >
Spring Data JPA and Null Parameters - Baeldung
We can add more query methods to our repository. For example, to ignore email, we can add a method that only accepts name:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found