chocoteam / choco-solver

An open-source Java library for Constraint Programming
http://choco-solver.org/
BSD 4-Clause "Original" or "Old" License
688 stars 138 forks source link

[BUG] Invalid field accessibility from choco-sat:1.0.2 #739

Closed rloic closed 4 years ago

rloic commented 4 years ago

Behavior

Runtime exception occurs when using s.setNoGoodRecordingFromRestarts();. It's due to the accessibility level of some fields in the class SatSolver in the submodule choco-sat:1.0.2. The given error msg is the following:

Exception in thread "main" java.lang.IllegalAccessError: class org.chocosolver.solver.constraints.nary.sat.PropNogoods tried to access field org.chocosolver.sat.SatSolver.ok_ (org.chocosolver.solver.constraints.nary.sat.PropNogoods and org.chocosolver.sat.SatSolver are in unnamed module of loader 'app')
    at org.chocosolver.solver.constraints.nary.sat.PropNogoods.propagate(PropNogoods.java:156)
    at org.chocosolver.solver.propagation.PropagationEngine.execute(PropagationEngine.java:225)
    at org.chocosolver.solver.propagation.PropagationEngine.activatePropagators(PropagationEngine.java:209)
    at org.chocosolver.solver.propagation.PropagationEngine.propagate(PropagationEngine.java:173)
    at org.chocosolver.solver.search.loop.propagate.PropagateBasic.execute(PropagateBasic.java:46)
    at org.chocosolver.solver.Solver.initialize(Solver.java:367)
    at org.chocosolver.solver.Solver.solve(Solver.java:255)
    at Example.main(Example.java:24)

The IDE indicates that `` is trying to access a field outside its package:

// module choco-solver
package org.chocosolver.solver.constraints.nary.sat;
public class PropNogoods extends Propagator<Variable> {
    ...
    @Override
    public void propagate(int evtmask) throws ContradictionException {
        initialize();
        if (!sat_.ok_) fails(); // sat_.ok_ is package private
        fp.clear();
        sat_.cancelUntil(0); // sat_.cancelUntil(0) is also package private
        storeEarlyDeductions();
        applyEarlyDeductions();
        for (int i = 0; i < vars.length; ++i) {
            doVariableBound(vars[i]);
        }
        while (fp.size() > 0) {
            doVariableBound(fp.pollFirst());
        }
    }
    ...
}
// module choco-sat
public class SatSolver implements SatFactory {
   ...

   boolean ok_; // The field ok_ is package private.

  ...
}

Possible Solution

Fixing scope accessibility.

Steps to Reproduce (for bugs)

A gradle project to reproduce the bug is available at: https://github.com/rloic/choco-sat-bug

Environment

cprudhom commented 4 years ago

This is related to #730 and already fixed in the masterbranch. As soon as I'm ready, I will release a new version.

rloic commented 4 years ago

:+1: I didn't see the previous issue. Thank you by the way. :smile: