AP.context.getContext throw null reference

I’ve been developing an add-on for jira and it’s been working rather well until I published, removed my manually added add (manually specified, self-hosted atlassian-connect.json) and added a private listing of my add-on (I’m testing the market place works as expected before pushing it public).

However I’m now getting odd issues. If I don’t have a debugging console active, when I call for AP.context.getContext nothing happens. No exceptions, the callback method isn’t called and nothign in the console other than the normal noise about “‘triggerPrivacyPolicySafeEvent’ has been deprecated” and [Simple-XDM] Failed to validate origin"… however if I turn on a debugging console I’ll get a null reference exception logged in the console:

  TypeError: a is null batch.js
    getContext batch.js
    vb</a.prototype._handleRequest batch.js
    vb</b.prototype._receiveMessage batch.js
    <anonymous>

decompiling the batch.js file I found the very first line of getContext is failing:

  getContext: function (a) {
    var b = d(a._context.extension);

Inspecting all arguments sent to the method I get an array with

  0: null
  1:d()
  callee:getContext()
  length: 2​​
  Symbol(Symbol.iterator):values()

Inspecting d(), the second argument, I get an object with _context with the obvious extension property that matches my add-on.

So the question I have is why would this add-on fail simply because I’ve listed it in the Atlassian Marketplace and installed it as a private listed add-on?

What have I miss-configured in the listing?

I’ll clarify that my add-on has one webPanel(s) and several jiraReports.

The webPanel appears to work fine… the reports are throwing the errors.

Also the reports double load the menu.

image

OK. Closer testing has shown all my reports will randomly double load the JIRA/Atlassian menu (as in the screenshot above).
Two reports will actually load.
One report has the first described error of not producing errors unless the debugging console is open.

I’m dynamically loading all.js - which I’m assuming bootstraps batch.js as follows

$scope.hostBaseUrl = getParameterByName('xdm_e') + getParameterByName('cp');

// add all.js from the host to this page
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.type = "text/javascript";
script.src = $scope.hostBaseUrl + '/atlassian-connect/all.js';
script.setAttribute('data-options', 'sizeToParent:true;hideFooter:true;base:true');
script.onreadystatechange = function () {
	if (this.readyState === 'complete') {
		main();
	}
};
script.onload = main;
head.appendChild(script);

The call to AP.context.getContext is within main;

I’m also seeing API calls to Jira failing on my instance:

/rest/internal/2/log/safe/error
{"sentFrom":"jira.frontend.navigation-next.shortcuts.repository","message":"There was a problem loading or     integrating with repository shortcuts","event":"Unable to load bridge \"repository-shortcuts/navigation-next\"","buildKey":"JF-PROD-9317","logTime":"2019-01-20T22:18:47.900Z","browserName":"Firefox","browserVersion":"64.0"}

with the response

{"errorMessages":["Can not instantiate value of type [map type; class java.util.LinkedHashMap, [simple type, class java.lang.String] -> [simple type, class java.lang.String]] from JSON String; no single-String constructor/factory method (through reference chain: com.atlassian.jira.rest.internal.v2.logging.LoggingBean[\"event\"])"]}

I’ve tracked down the cause of the double menu occurring. If the call to:

/rest/api/2/user/properties/navigation_next_collapse_affordance_change_boarding_data?username=

returns a 404, the menu works as expected.
if it returns something in the order of

{"key":"navigation_next_collapse_affordance_change_boarding_data","value":{"dateSeenChangeBoarding":123456789}}

then double menus will occur.

That seems like some sort of bug.

2 Likes

The original issue of the call to AP.context.getContext not doing anything I’ve suppressed with a setInterval - far from right, but at-least it works… there’s something to do with runtime issues going on here.

What is the recommended issue to avoid concurrency issues?