Problem deleting branch

I am trying to delete a branch using this api: https://docs.atlassian.com/bitbucket-server/rest/6.3.1/bitbucket-branch-rest.html#idp2

I get a 500 back. The log says:

2019-06-04 15:46:49,944 ERROR [http-nio-8080-exec-382] xxxxxx@xxxxxxxx xxxxxx xx.xx.xx.xx,127.0.0.1 “POST /rest/api/1.0/projects/XXXXXX/repos/xxxxxxx/branches HTTP/1.0” c.a.s.i.r.e.DefaultUnhandledExceptionMapperHelper Unhandled exception while processing REST request: “POST /rest/api/1.0/projects/XXXXXX/repos/xxxxxxx/branches HTTP/1.0”

Body is:
{“dryRun”:“false”,“name”:“refs/heads/feature/INT-339_fel_profile”}

We cannot increse log levels because of high load.

We are using Atlassian Bitbucket v5.8.0·

Any help appreciated.

I do a DELETE, but the log says POST

Hi Marten, can you please provide more of the stack trace in the logs?

I have tried sending the displayId. I have tried using “id” instead of “name”.

I have asked for a stack trace.

2019-06-04 15:46:49,944 ERROR [http-nio-8080-exec-382] xxx.xxxxxx @1EEOS97x946x23379045x1 1lg0jtm xx.xx.xx.xx,127.0.0.1 "POST /rest/api/1.0/projects/APPII_FUSE_EXT/repos/extinf-ssbt-v8-a
pp/branches HTTP/1.0" c.a.s.i.r.e.DefaultUnhandledExceptionMapperHelper Unhandled exception while processing REST request: "POST /rest/api/1.0/projects/APPII_FUSE_EXT/repos/extinf-ssbt-v8-app/b
ranches HTTP/1.0"
java.lang.NullPointerException: startPoint
        at java.util.Objects.requireNonNull(Objects.java:228)
        at com.atlassian.bitbucket.util.BuilderSupport.requireNonBlank(BuilderSupport.java:86)
        at com.atlassian.bitbucket.util.BuilderSupport.checkNotBlank(BuilderSupport.java:73)
        at com.atlassian.bitbucket.repository.AbstractCreateRefRequest$AbstractBuilder.<init>(AbstractCreateRefRequest.java:71)
        at com.atlassian.bitbucket.repository.CreateBranchRequest$Builder.<init>(CreateBranchRequest.java:17)
        at com.atlassian.stash.internal.rest.repository.BranchResource.lambda$createBranch$0(BranchResource.java:74)
        at com.atlassian.stash.internal.rest.repository.BranchResource$$Lambda$2604/1211865235.apply(Unknown Source)
        at com.atlassian.stash.internal.rest.repository.AbstractRepositoryRefResource.process(AbstractRepositoryRefResource.java:25)
        at com.atlassian.stash.internal.rest.repository.BranchResource.createBranch(BranchResource.java:73)
        at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
        at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
        at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
        at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
        at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
        at com.atlassian.analytics.client.filter.UniversalAnalyticsFilter.doFilter(UniversalAnalyticsFilter.java:92)
        at com.atlassian.analytics.client.filter.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:39)
        at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
        at com.atlassian.plugin.connect.plugin.auth.scope.ApiScopingFilter.doFilter(ApiScopingFilter.java:81)
        at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
        at com.atlassian.stash.internal.spring.security.StashAuthenticationFilter.onSuccess(StashAuthenticationFilter.java:219)
        at com.atlassian.stash.internal.spring.security.StashAuthenticationFilter.doFilter(StashAuthenticationFilter.java:100)
        at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doInsideSpringSecurityChain(BeforeLoginPluginAuthenticationFilter.java:112)
        at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doFilter(BeforeLoginPluginAuthenticationFilter.java:75)
        at com.atlassian.security.auth.trustedapps.filter.TrustedApplicationsFilter.doFilter(TrustedApplicationsFilter.java:94)
        at com.atlassian.oauth.serviceprovider.internal.servlet.OAuthFilter.doFilter(OAuthFilter.java:67)
        at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
        at com.atlassian.plugin.connect.plugin.auth.oauth2.DefaultSalAuthenticationFilter.doFilter(DefaultSalAuthenticationFilter.java:69)
        at com.atlassian.plugin.connect.plugin.auth.user.ThreeLeggedAuthFilter.doFilter(ThreeLeggedAuthFilter.java:109)
        at com.atlassian.jwt.internal.servlet.JwtAuthFilter.doFilter(JwtAuthFilter.java:32)
       at com.atlassian.analytics.client.filter.DefaultAnalyticsFilter.doFilter(DefaultAnalyticsFilter.java:38)
        at com.atlassian.analytics.client.filter.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:39)
        at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
        at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doBeforeBeforeLoginFilters(BeforeLoginPluginAuthenticationFilter.java:90)
        at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doFilter(BeforeLoginPluginAuthenticationFilter.java:73)
        at com.atlassian.stash.internal.request.DefaultRequestManager.doAsRequest(DefaultRequestManager.java:89)
        at com.atlassian.stash.internal.hazelcast.ConfigurableWebFilter.doFilter(ConfigurableWebFilter.java:38)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.lang.Thread.run(Thread.java:745)
        ... 239 frames trimmed

Hi @marten.gustafsson, thanks for the info!

It looks like you’re hitting the wrong URL. To delete a branch the URL you need is <base-url>/rest/branch-utils/1.0/projects/{projectKey}/repos/{repositorySlug}/branches (note: not .../rest/api/...).
The documentation is here.

As for the 500 you received, that shouldn’t have happened. I have raised a bug so that in the future you receive a 400 response code with an appropriate error message: https://jira.atlassian.com/browse/BSERV-11803

Hope that helps!
Kristy

Still 500 and exception!

Body:
{"dryRun":"false","name":"refs/heads/feature/testing"}
Headers:

        conn.setRequestProperty( 'Authorization', token_header)
        conn.setRequestProperty( 'Method', 'DELETE')
        conn.setRequestProperty( 'User-Agent', 'groovy-2.4.9' )
        conn.setRequestProperty( 'Accept', 'application/json' )
        conn.setRequestProperty( 'Content-Type', 'application/json' )
2019-06-12 06:46:17,210 ERROR [http-nio-8080-exec-700] xxxx.xxxx@1EEOS97x406x35262116x0 1cv79nl xx.xx.xx.xx,0:0:0:0:0:0:0:1 "POST /rest/branch-utils/1.0/projects/APPII_FUSE_HOKO/repos/hoko-sjuklonekostnader-app/branches HTTP/1.0" c.a.s.i.r.e.DefaultUnhandledExceptionMapperHelper Unhandled exception while processing REST request: "POST /rest/branch-utils/1.0/projects/APPII_FUSE_HOKO/repos/hoko-sjuklonekostnader-app/branches HTTP/1.0"
java.lang.NullPointerException: startPoint
       at java.util.Objects.requireNonNull(Objects.java:228)
        at com.atlassian.bitbucket.util.BuilderSupport.requireNonBlank(BuilderSupport.java:86)
        at com.atlassian.bitbucket.util.BuilderSupport.checkNotBlank(BuilderSupport.java:73)
        at com.atlassian.bitbucket.repository.AbstractCreateRefRequest$AbstractBuilder.<init>(AbstractCreateRefRequest.java:71)
        at com.atlassian.bitbucket.repository.CreateBranchRequest$Builder.<init>(CreateBranchRequest.java:17)
        at com.atlassian.bitbucket.internal.branch.DefaultBranchService.createBranch(DefaultBranchService.java:79)
        at com.atlassian.bitbucket.internal.branch.rest.BranchUtilsResource.createBranch(BranchUtilsResource.java:85)
        at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
        at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
        at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
        at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
        at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
        at com.atlassian.analytics.client.filter.UniversalAnalyticsFilter.doFilter(UniversalAnalyticsFilter.java:92)
        at com.atlassian.analytics.client.filter.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:39)
        at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
        at com.atlassian.plugin.connect.plugin.auth.scope.ApiScopingFilter.doFilter(ApiScopingFilter.java:81)
        at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
        at com.atlassian.stash.internal.spring.security.StashAuthenticationFilter.onSuccess(StashAuthenticationFilter.java:219)
        at com.atlassian.stash.internal.spring.security.StashAuthenticationFilter.doFilter(StashAuthenticationFilter.java:100)
        at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doInsideSpringSecurityChain(BeforeLoginPluginAuthenticationFilter.java:112)
        at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doFilter(BeforeLoginPluginAuthenticationFilter.java:75)
        at com.atlassian.security.auth.trustedapps.filter.TrustedApplicationsFilter.doFilter(TrustedApplicationsFilter.java:94)
        at com.atlassian.oauth.serviceprovider.internal.servlet.OAuthFilter.doFilter(OAuthFilter.java:67)
        at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
        at com.atlassian.plugin.connect.plugin.auth.oauth2.DefaultSalAuthenticationFilter.doFilter(DefaultSalAuthenticationFilter.java:69)
        at com.atlassian.plugin.connect.plugin.auth.user.ThreeLeggedAuthFilter.doFilter(ThreeLeggedAuthFilter.java:109)
        at com.atlassian.jwt.internal.servlet.JwtAuthFilter.doFilter(JwtAuthFilter.java:32)
        at com.atlassian.analytics.client.filter.DefaultAnalyticsFilter.doFilter(DefaultAnalyticsFilter.java:38)
        at com.atlassian.analytics.client.filter.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:39)
        at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
        at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doBeforeBeforeLoginFilters(BeforeLoginPluginAuthenticationFilter.java:90)
        at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doFilter(BeforeLoginPluginAuthenticationFilter.java:73)
        at com.atlassian.stash.internal.request.DefaultRequestManager.doAsRequest(DefaultRequestManager.java:89)
        at com.atlassian.stash.internal.hazelcast.ConfigurableWebFilter.doFilter(ConfigurableWebFilter.java:38)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.lang.Thread.run(Thread.java:745)
        ... 239 frames trimmed

Can you please share what language and class you are using? To me, it looks like you’re using Java’s java.net.HttpURLConnection.
If this is correct, then your problem will be in conn.setRequestProperty('Method', 'DELETE'). It should be conn.setRequestMethod("DELETE"). But I can’t know for sure.
I’ll update BSERV-11803 to reflect that the 500 is coming from the branch-utils endpoint too because you should be getting a 400.

Groovy. Using Java UrlConnection. The created class is sun.net.www.protocol.http.HttpURLConnection

Using conn.setRequestMethod solved it. Thanks!