File: src/main/java/org/apache/commons/math/optimization/linear/SimplexTableau.java
Issue: Negative value with restrictNonNegative
Problem: commons-math-2.2 SimplexSolver.
A variable with 0 coefficient may be assigned a negative value nevertheless restrictToNonnegative flag in call:
SimplexSolver.optimize(function, constraints, GoalType.MINIMIZE, true);
Function
1 * x + 1 * y + 0
Constraints:
1 * x + 0 * y = 1
Result:
x = 1; y = -1;
Probably variables with 0 coefficients are omitted at some point of computation and because of that the restrictions do not affect their values.

Buggy code:
protected RealPointValuePair getSolution() {
  int negativeVarColumn = columnLabels.indexOf(NEGATIVE_VAR_COLUMN_LABEL);
  Integer negativeVarBasicRow = negativeVarColumn > 0 ? getBasicRow(negativeVarColumn) : null;
  double mostNegative = negativeVarBasicRow == null ? 0 : getEntry(negativeVarBasicRow, getRhsOffset());

  Set<Integer> basicRows = new HashSet<Integer>();
  double[] coefficients = new double[getOriginalNumDecisionVariables()];
  for (int i = 0; i < coefficients.length; i++) {
      int colIndex = columnLabels.indexOf("x" + i);
      if (colIndex < 0) {
        coefficients[i] = 0;
        continue;
      }
      Integer basicRow = getBasicRow(colIndex);
          // if the basic row is found to be the objective function row
          // set the coefficient to 0 -> this case handles unconstrained 
          // variables that are still part of the objective function
      if (basicRows.contains(basicRow)) {
          // if multiple variables can take a given value
          // then we choose the first and set the rest equal to 0
          coefficients[i] = 0 - (restrictToNonNegative ? 0 : mostNegative);
      } else {
          basicRows.add(basicRow);
          coefficients[i] =
              (basicRow == null ? 0 : getEntry(basicRow, getRhsOffset())) -
              (restrictToNonNegative ? 0 : mostNegative);
      }
  }
  return new RealPointValuePair(coefficients, f.getValue(coefficients));
}

Fixed code:
protected RealPointValuePair getSolution() {
  int negativeVarColumn = columnLabels.indexOf(NEGATIVE_VAR_COLUMN_LABEL);
  Integer negativeVarBasicRow = negativeVarColumn > 0 ? getBasicRow(negativeVarColumn) : null;
  double mostNegative = negativeVarBasicRow == null ? 0 : getEntry(negativeVarBasicRow, getRhsOffset());

  Set<Integer> basicRows = new HashSet<Integer>();
  double[] coefficients = new double[getOriginalNumDecisionVariables()];
  for (int i = 0; i < coefficients.length; i++) {
      int colIndex = columnLabels.indexOf("x" + i);
      if (colIndex < 0) {
        coefficients[i] = 0;
        continue;
      }
      Integer basicRow = getBasicRow(colIndex);
      if (basicRow != null && basicRow == 0) {
          // if the basic row is found to be the objective function row
          // set the coefficient to 0 -> this case handles unconstrained 
          // variables that are still part of the objective function
          coefficients[i] = 0;
      } else if (basicRows.contains(basicRow)) {
          // if multiple variables can take a given value
          // then we choose the first and set the rest equal to 0
          coefficients[i] = 0 - (restrictToNonNegative ? 0 : mostNegative);
      } else {
          basicRows.add(basicRow);
          coefficients[i] =
              (basicRow == null ? 0 : getEntry(basicRow, getRhsOffset())) -
              (restrictToNonNegative ? 0 : mostNegative);
      }
  }
  return new RealPointValuePair(coefficients, f.getValue(coefficients));
}