System.err.println("Unable to create group " + g); System.exit(1);
throw new RuntimeException("Unable to create group " + g);
  protected static boolean groupAdd(GrouperSession s, GrouperGroup g) {    boolean rv      = false;    Session session = GrouperBackend._init();    GrouperAttribute stem = (GrouperAttribute) g.attribute("stem");    if (GrouperBackend._stemLookup(s, session, (String) stem.value())) {      try {        Transaction t = session.beginTransaction();        // The Group object        session.save(g);        // The Group schema        GrouperSchema schema = new GrouperSchema( g.key(), g.type() );        session.save(schema);        // The Group attributes        Map       attributes  = g.attributes();        Iterator  iter        = attributes.keySet().iterator();        while (iter.hasNext()) {          // FIXME WTF?          GrouperAttribute attr = (GrouperAttribute) attributes.get( iter.next() );          // TODO Error checking, anyone?           GrouperBackend._attrAdd(                                  session, g.key(),                                   attr.field(), attr.value()                                 );        }                /*         * I need to commit the group to the groups registry before         * granting the ADMIN privs as the act of granting, especially if         * using the default access privilege implementation, may need to         * load the group from the groups registry.  If it hasn't been         * committed, that will obviously fail and Java will go BOOM!         *         * Of course, this may make rolling back even the granting fails         * even more interesting.         */        t.commit();        // We need a root session for for bootstrap privilege granting        Subject         rootS = GrouperSubject.load(                                  Grouper.config("member.system"),                                  Grouper.DEF_SUBJ_TYPE                                );        GrouperSession  roots = GrouperSession.start(rootS);        // And grant ADMIN privilege to the list creator        Grouper.log().backend("Converting subject " + s);        GrouperMember m       = GrouperMember.load( s.subject() );        boolean       granted = false;        if (m != null) { // FIXME Bah          Grouper.log().backend("Converted to member " + m);          // NS_TYPE groups get `STEM', not `ADMIN'          if (g.type().equals(Grouper.NS_TYPE)) {            if (Grouper.naming().grant(roots, g, m, "STEM") == true) {              Grouper.log().backend("Granted STEM to " + m);              t.commit(); // XXX Is this commit necessary?              granted = true;              rv      = true;            } else {              Grouper.log().backend("Unable to grant STEM to " + m);            }          } else {            // For all other group types default to `ADMIN'            if (Grouper.access().grant(roots, g, m, Grouper.PRIV_ADMIN)) {              Grouper.log().backend("Granted ADMIN to " + m);              t.commit(); // XXX Is this commit necessary?              granted = true;              rv      = true;            } else {              Grouper.log().backend("Unable to grant ADMIN to " + m);            }          }        } else {          Grouper.log().backend("Unable to convert to member");        }        // Close root session        roots.stop();        if (granted == false) {          /*           * TODO Rollback?  Exception?  The rollback would also need to           *      rollback the granting of the ADMIN privilege.  Or at           *      least try to.           */          System.err.println("Unable to create group " + g);          System.exit(1);        }      } catch (Exception e) {        // TODO We probably need a rollback in here in case of failure        //      above.        System.err.println(e);        System.exit(1);      }    } else {       System.err.println("STEM " + stem.value() + " DOES NOT EXIST!");      Grouper.log().event(        "Unable to add group as stem=`" + stem.value() + "' does not exist."      );    }    GrouperBackend._hibernateSessionClose(session);    return rv;  }