"The Lord judges the peoples; Judge me, O Lord, according to my righteousness and according to the integrity that is in me." (Ps. 7:8)
"Vindicate me, O Lord, for I have walked in my integrity, and I have trusted in the Lord without wavering, Prove me, O Lord, and try me; test my heart and my mind. For your steadfast love is before my eyes, and I walk in your faithfulness..." (Ps. 26:1-2)
These are only a few statements like these in the Psalms, but if I'm honest, sometimes I look at such verses and think "How can he (the writer) say that?!" "Isn't that self-righteous?!" The answer: NO! Bonhoeffer clarifies why the Psalmist makes statements like these as often as he makes statements concerning repentance, confession of sin, and spiritual depression. Ill quote him at length.
"It is often particularly striking and offensive to evangelical Christians that in the Psalms the innocence of devout people is spoken of at least as often as is their guilt. (cf. Psalms 5, 7, 9, 16, 17, 26, 35, 41, 44, 59, 66, 68, 69, 73, 86, and others.) Here it seems obvious that there is a vestige of the so-called Old Testament works righteousness, with which the Christian can no longer begin. Yet this outlook is completely superficial and knows nothing of the depth of the Word of God. It is clear that a man can speak of his own innocence in a self-righteous way, but do we not also realize that a man can pray the most humble confession of sin very self-righteously? Talk about ones own guilt can be just as far from the Word of God as talk about one's innocence. But the question is not which possible motives may stand behind the prayer, but whether the content of the prayer itself is appropriate or inappropriate. And here it is clear that the believing Christian certainly has to say not only something about his guilt but also something about his innocence and his justification. It is characteristic of the faith of the Christian that through God's grace and the merit of Jesus Christ, he has become entirely justified and guiltless in God's eyes, so that "there is therefore now no condemnation for those who are in Christ Jesus" (Romans 8:1). And it is characteristic of the prayer of the Christian to hold fast to this innocence and justification which has come to him, appealing to God's word and thanking for it. So not only are we permitted, but directly obligated - provided we take God's action to us at all seriously- to pray in all humiliation and certainty: " I was blameless before him and I kept myself from guilt" ( Psalm 18:23); " If thou testeth me thou will find no wickedness in me" (Psalm 17:3). With such a prayer we stand in the center of the New Testament, in the community of the cross of Jesus Christ."
We are "permitted" and "directly obligated" on the basis of God's justifying us as sinners, to say and to pray with confidence and with assurance, with all humility and thankfulness, that " I was blameless before him, and I kept myself from guilt". This is wonderful! Christ is praying through the Psalms on our behalf, and because His righteousness and perfect obedience has been imputed to us, God now sees Christ in his blamelessness and perfection when He sees us. We are able to pray with this same assurance as the Psalmist because the cross is before us, and Christ's blood and righteousness has been counted to us.