Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to manage 'java.lang.NullPointerException: state' at at com.atlassian.stash.internal.build.BuildStatusServiceImpl.findAll() method?

Dana
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2014

Good day!

I am use BuildStatusService in my plugin. Like this (MyClass.java):

private String getFromCommitId(PullRequest pullRequest) {
    return pullRequest.getFromRef().getLatestChangeset();
}

public Iterable<? extends BuildStatus> getBuildStatusList(PullRequest pr) { 
String changeset = getFromCommitId(pr);
return buildStatusService.findAll(changeset).getValues();
}

But NullPointerException is often (not always) in stacktrace:

c.a.s.i.p.DefaultMergeRequestCheckService Merge request check <> of type <> failed.
java.lang.NullPointerException: state
        at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:204) ~[guava-10.0.1.jar:na]
        at com.atlassian.stash.internal.build.InternalBuildStatus.<init>(InternalBuildStatus.java:20) ~[na:na]
        at com.atlassian.stash.internal.build.BuildStatusServiceImpl$3.apply(BuildStatusServiceImpl.java:98) ~[na:na]
        at com.atlassian.stash.internal.build.BuildStatusServiceImpl$3.apply(BuildStatusServiceImpl.java:96) ~[na:na]
        at com.google.common.collect.Iterators$8.next(Iterators.java:782) ~[guava-10.0.1.jar:na]
        at com.google.common.collect.Lists.newArrayList(Lists.java:139) ~[guava-10.0.1.jar:na]
        at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:269) ~[guava-10.0.1.jar:na]
        at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:230) ~[guava-10.0.1.jar:na]
        at com.atlassian.stash.internal.build.BuildStatusServiceImpl.findAll(BuildStatusServiceImpl.java:64) ~[na:na]
        at com.sun.proxy.$Proxy1024.findAll(Unknown Source) ~[na:na]
        at MyClass(MyClass.java:7) ~[na:na]

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2014

HI Dana,

You must have a null value in your AO_CFE8FA_BUILD_STATUS in the 'state' column. That should be impossible. The only public way to add a row is via REST (and thus BuildStatusResource) which checks that 'state' is never null.

Charles

Alexey_Efimov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2014

Hello Charles,

mysql> select state, count(csid) from AO_CFE8FA_BUILD_STATUS group by state;
+------------+-------------+
| state      | count(csid) |
+------------+-------------+
| FAILED     |        1719 |
| INPROGRESS |         268 |
| SUCCESSFUL |        5621 |
+------------+-------------+
3 rows in set (0.05 sec)

We check it since we get this NPE. No null in database.

cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2014

Hi Alexey,

I'm assuming you've looked at AoBuildStatusDao. I can't see any other way that you would get an NPE. Are you sure that query will group by null? How many total rows are there in that table if you don't group by?

Cheers,

Charles

cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2014

Hmm. Damn, it looks like GROUP BY does group on nulls.

Sorry Alexey/Dana, I've never seen that error before and I can offer no explanation as to why it might be happening.

cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2014

Hi Alexy,

At this point I'm afraid the only thing we can do is raise a support ticket and go from there.

We should be able to send you an updated version of the build-integration plugin with some extra debugging that will tell us what row is broken and what the value of state is.

Cheers,

Charles

Alexey_Efimov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2014

Charles, can it be one of follow:

1. jar hell in dependencies (but build-integration is part of stash and we use provided only)?

2. We also invoke add(BuildStatus) with own fake implementation, to add INPOGRESS build until CI server really starts it. Can it affect?

cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2014

Hi Alexey,

Can you show us the code that adds the build status? I'm assuming this, or something like it, is the cause of the problem. It's less likely to be jar hell.

Cheers,

Charles

Dana
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2014

There was a problem with authorization. Because MergeCheck turns on "READ-ONLY" by "Transactional" annotation& So we have decided to add status in parallel therad with SecurityService. Like this:

Future<String> changesetF = executorService.submit(new Callable<String>() {
        @Override
        public String call() {
            try {
                String authMessage = "Adding IN_PROGRESS status for queued build";
                String user = "bot-user";
                String changeset = securityService.doAsUser(
                        authMessage,
                        user,
                        new OperationGrantPermission<String>(
                            securityService,
                            new UncheckedOperation<String>() {
                                @Override
                                public String perform() {
                                    try {
                                        String commit = getBuildChangeset(pullRequest);
                                        buildStatusService
                                            .add(commit, new TeamcityIntegrationBuildStatus(buildId));
                                        return commit;
                                    } catch (Exception e) {
                                        throw new RuntimeException(e);
                                    }
                                }
                            },
                            authMessage,
                            Sets.newHashSet(Permission.REPO_WRITE, Permission.LICENSED_USER)));
                return changeset;
            } catch (Throwable e) {
                log.error("Error while storing build status", e);
                throw new RuntimeException(e);
            }
        }
    });

Alexey_Efimov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2014
public class TeamcityIntegrationBuildStatus implements BuildStatus {
    ...
    @Nonnull
    @Override
    public State getState() {
        return State.INPROGRESS;
    }
    ...
}

cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 14, 2014

Hi guys,

Ok I have nothing. I can see no conceiveable way that State would be null. My suggestion, given that you compile from source, is to put some debugging into the offending code and figure out what database row is broken. I'm sorry I can't help any more than that. :(

Charles

TAGS
AUG Leaders

Atlassian Community Events