I know that the way we calculate in Fermat's principle in optics is to take the path length (as an integral) and demand that it be stationary to first order. Now this approach is mathematically the same as calculating a geodesic, or finding stationary action, namely we use the calculus of variations. In the last two cases there are times when we use this to find the longest possible path. The example that I am thinking of is in relativity where we find the geodesic by making the "proper time" be as long as possible i.e. the real path (the geodesic) through spacetime will be the one for which the time elapsed for the particle taking this path is longest. The mathematics of a geodesic through spacetime and Fermat's pinciple however, are the same. I know that in the handfull of experiments that I have done, the light takes the shortest path. However given the math I can't think of a reason why the light cant take the longest path and still satisfy Fermat's principle. Are there cases where this actually happens? If not, why not?