</BUG>
while (index != -1) {
group.getLayers().remove(index);
group.getStyles().remove(index);
<BUG>index = group.getLayers().indexOf(layerGroupToRemove);
</BUG>
}
if (group.getLayers().size() == 0) {
visit(group);
} else {

Filter associatedTo = Predicates.equal("layers.id", layerGroupToRemove.getId(), MatchAction.ANY);
try (CloseableIterator<LayerGroupInfo> it = catalog
.list(LayerGroupInfo.class, associatedTo)) {
while (it.hasNext()) {
LayerGroupInfo group = it.next();
int index = getLayerGroupIndex(layerGroupToRemove, group);
while (index != -1) {
group.getLayers().remove(index);
group.getStyles().remove(index);
index = getLayerGroupIndex(layerGroupToRemove, group);
}
if (group.getLayers().size() == 0) {
visit(group);
} else {
