Yes it's a bad smell, and you should use the equals() method instead, as explained @arshajii above.
What I've found most intriguing is the fact that such comparison might even work sometimes, like starting with small values (-128 to 127), and will break for larger numbers. For example:
@Test
public void compareSmallIds() {
Long id1 = 127L;
Long id2 = 127L;
Assert.assertTrue(id1 == id2);
Assert.assertTrue(id1.equals(id2));
Assert.assertTrue((long) id1 == (long) id2);
Assert.assertTrue(id1.longValue() == id2.longValue());
}
@Test
public void compareIds() {
Long id1 = 500L;
Long id2 = 500L;
Assert.assertFalse(id1 == id2);
Assert.assertTrue(id1.equals(id2));
Assert.assertTrue((long) id1 == (long) id2);
Assert.assertTrue(id1.longValue() == id2.longValue());
}
It seems this behavior is based on number cache policy definition, with byte values range as default. But definitely, code with non-primitive values should not rely on the == operator for value comparison!