Term tmp, tmp2;
Term[] list;
a1 = a1.dereference();
if (a1.isVariable()) {
throw new PInstantiationException(this, 1);
} else if (a1.equals(Nil)) {
if (!a2.unify(Nil, engine.trail)) {
return engine.fail();
}
return cont;
} else if (!a1.isList()) {
throw new IllegalTypeException(this, 1, "list", a1);
}
len = ((ListTerm) a1).length();
list = new Term[len];
tmp = a1;
for (int i = 0; i < len; i++) {
if (!tmp.isList()) {
throw new IllegalTypeException(this, 1, "list", a1);
}
list[i] = ((ListTerm) tmp).car().dereference();
tmp = ((ListTerm) tmp).cdr().dereference();
}
if (!tmp.equals(Nil)) {
throw new PInstantiationException(this, 1);
}
try {
Arrays.sort(list);
} catch (ClassCastException e) {
throw new JavaException(this, 1, e);