The Law-keeping Jew is guilty of the very sins of which he accuses the Gentiles, and is therefore under God’s judgment. A Jewish opponent in the Second Temple period may have thought that circumcision and keeping the Law was sufficient to avoid the wrath of God being revealed (1:18). In this paragraph, Paul continues to engage a hypothetical dialogue partner who might think obedience to key boundary markers of Judaism will be of some benefit on the Day of Judgment. Paul argues here it is not at all sufficient to avoid judgment, since being circumcised means nothing if the righteous requirements of the Law are not fully kept.

But as E. P. Sanders famously declared, the Judaism of the Second Temple period was not a “works for salvation” religion at all. God’s gracious choice of Israel as his people and his gift of the covenant was want made the Jews God’s people and their appropriate response was keeping the Law. No Jew thought they were earning salvation by keeping the Law, it was simply their responsibility as God’s chosen people. Sanders pointed out that the common legalistic view of Judaism had more to do with Luther’s response to Roman Catholicism and the subsequent Reformation theology than Paul’s dialogue with Jews in Romans.
Yet Paul seems to claim here his opponent relies on the law and boasts in God. It is true some streams of Second Temple Judaism did see the Law as a guarantee of salvation. 2 Baruch was written about thirty years after Romans as a response to the destruction of Jerusalem in A.D. 70. The writer of this apocalypse seems to say keeping God’s statutes will preserve the Jewish people, implying the recent destruction of Jerusalem was the result of unfaithfulness.
2 Baruch 48:22-23 In you we have put our trust, because, behold, your Law is with us and we know that we do not fall as long as we keep your statutes. We shall always be blessed; at least, we did not mingle with the nations.
The Greek verb Paul uses in Romans 2:17 translated “rely” (ἐπαναπαύομαι) has the sense of comfort or support, sometimes “rest.” To rely on the Law is to think of it as providing security. Certainly the 2 Baruch quote above supports Jewish reliance on the Law for their blessing and security. Even in the Old Testament, there was always an “if” to the Mosiac covenant; if you keep the Law you will be blessed. The alternative was the curse of the Law, non-blessing and eventually exile from the Law.
This reliance on the Law is combined with boasting in God. Jeremiah 9:23-24 and Deuteronomy 4:7-8 both celebrate the special relationship between God and Israel. Paul agrees the Law is “the embodiment of knowledge and truth” (v. 20), but one cannot rely on the Law when God’s judges because (as he will argue in this paragraph), not even the Jews who possess the Law keep the Law. After all, the Jews are still in exile and they are not experiencing the blessing of God!
What is Paul doing in Romans 2? Is he over-stating the Jewish boast in the Law? Is he making a straw-man argument against Judaism? Even if he is, this over-reliance on religion seems to be a very applicable point to contemporary church.
Even if Paul was not addressing a specific thread of Judaism in his day, this condemnation of boasting may very well speak powerfully to the church today.
Boasting in the law can be a very dangerous and harmful thing to do. In the modern sense it could be boasting about how well you follow a moral lifestyle and how you abstain from all that is deemed wrong in your eyes. This can turn people off to you and shut off any chance of you sharing the Gospel message of hope in the resurrected Jesus. I can recall times where I’ve been in Bible studies where people boast about their knowledge of what’s right and wrong and how well they follow it and even go as far as condemning other Christians who struggle with certain sin as “lukewarm Christians”. We are all born sinners and the proper way to address what you see as sinful in a believer is to not attack their level of faith in your eyes but to build up and encourage them first in Christ. Maybe getting to know them a little more before you attack personal beliefs or what they are struggling with. Boasting turns people away from what you could be talking about.