$ opam install --deps-only --locked infer .
[starting in an empty switch, this installs all the dependencies at the correct version]
$ opam upgrade
...
↗ upgrade javalib 2.3.5 to 3.0
↗ upgrade sawja 1.5.4 to 1.5.6
...
$ opam install --deps-only --locked infer .
Nothing to do.
$ # javalib has not been downgraded to 2.3.5
$ opam show javalib --field=version
3.0
Consider for instance this opam.locked file. I would expect opam to downgrade javalib in this scenario (since the file specifies version 2.3.5) but it doesn't: