Crash when a Text Axis doesn't match its workspace

Expected behavior

Attempting to attach a Text Axis to a workspace should fail if it is the wrong length

Actual behavior

The script completes successfully. Subsequently, attempting to open the workspace window gives the Mantid error report “terminate/continue” instead. “Plot All” gives a plot of those spectra for which an axis value is available to label them, and the error report. Overwriting a good workspace, already open in its window, with one with a mismatched axis gives an infinite loop of terminate/continue boxes.

Steps to reproduce the behavior

Try the following script and then open the workspace:

w=WorkspaceFactory.create("Workspace2D",NVectors=3,XLength=10,YLength=10)
axis1=TextAxis.create(2)
for k,mn in enumerate(("one","two")):
    axis1.setLabel(k,mn)
w.replaceAxis(1,axis1)
AnalysisDataService.addOrReplace("foo",w)

Platforms affected

Observed on MantidPlot 4.0 and a more recent nightly build (Windows)

I have now tried it on Mantid Workbench (4.0) with very similar results. Opening the workspace gives three consecutive terminate/continue boxes, meanwhile a workspace window does appear with the top two spectra named. Then the whole of Workbench crashes.