
52 P.3d 150 (2002)
TRU-LINE METAL PRODUCTS, INC., Jody Sutherland, and Craig Holley, Appellants,
v.
U.S. FABRICATION & ERECTION, Appellee.
No. S-9790.
Supreme Court of Alaska.
June 7, 2002.
Rehearing Denied August 9, 2002.
*151 Susan Orlansky and Jeffrey M. Feldman, Feldman & Orlansky, Anchorage, for Appellants.
Bruce E. Davison and Joseph A. Pollock, Davison & Davison, Anchorage, for Appellee.
Before: FABE, Chief Justice, MATTHEWS, EASTAUGH, BRYNER, and CARPENETI, Justices.

OPINION
CARPENETI, Justice.

I. INTRODUCTION
In this contract dispute, Tru-Line Metal Products, Inc. sued United States Fabrication and Erection (USF & E) in federal court. The federal court granted summary judgment in favor of USF & E and awarded full attorney's fees as a sanction for filing a baseless claim. Tru-Line then brought this action in state superior court. USF & E moved for summary judgment on res judicata grounds. The superior court granted summary judgment and awarded USF & E three times actual attorney's fees and costs as a sanction under Alaska Rules of Civil Procedure 11 and 95. Because the federal court did not have subject matter jurisdiction, res judicata does not bar Tru-Line from filing suit in state court on the same claim. We therefore reverse the grant of summary judgment and remand for further proceedings in the superior court.

II. FACTS AND PROCEEDINGS

A. Background
In 1994 M.A. Mortensen entered into a contract with the United States Army Corps of Engineers for improvements to Elmendorf Composite Medical Facility. Mortensen entered into a subcontract with Waiward Steel Fabricators, Ltd., which in turn entered into a subcontract with United States Fabrication and Erection. In October 1994 USF & E, as principal, and Star Insurance Company (Star), as surety, executed a payment bond, *152 guaranteeing payment of all persons having a direct relationship with either USF & E or a subcontractor of USF & E. In February 1995 USF & E, as a second-tier subcontractor on the Elmendorf project, entered into a subcontract with Tru-Line Metal Products, Inc. to install metal decking.

B. The Federal Court Lawsuit
In May 1997 Tru-Line filed suit against USF & E and Star in United States District Court in Anchorage, alleging breach of contract and claiming damages totaling over $730,000, plus interest, costs, and attorney's fees. In its complaint, Tru-Line asserted that the federal court had federal question jurisdiction pursuant to 28 U.S.C. § 1331 and by virtue of the Miller Act.[1] USF & E and Star moved for summary judgment, arguing that Tru-Line's claims were barred under the Miller Act. USF & E and Star also contended that, because Tru-Line was not registered as a contractor in the State of Alaska pursuant to AS 08.18.151,[2] it was not entitled to enforce its contract with USF & E.
Tru-Line attempted to amend its complaint in September 1997. The amended complaint purported to establish diversity of citizenship as another ground for federal jurisdiction. However, Tru-Line failed to note diversity in the heading, did not allege any facts establishing diversity in the pleadings, and stated the incorrect jurisdictional amount. At oral argument on the motion for summary judgment, United States District Court Judge John W. Sedwick, noting these substantial defects in the amended complaint, allowed counsel for Tru-Line to withdraw the amended complaint and file another. (Tru-Line never filed a second amended complaint.) Judge Sedwick also stated that he saw no valid claim based upon the Miller Act.[3] He indicated that he would consider the other matters with respect to the state law issues, that is whether Tru-Line, as an unregistered contractor, could sue on its contract. He expressed skepticism that Tru-Line could do so.[4]
In his written order from chambers, Judge Sedwick granted summary judgment to USF & E. He found that, because Tru-Line was a third-tier contractor and because the Star payment bond was not a Miller Act bond, Tru-Line was not entitled to recover under the Miller Act. Judge Sedwick also discussed the Alaska contractor registration law and its applicability to Tru-Line's claims. He found the Alaska Contractor Registration Act to be substantive in nature and applicable to Tru-Line's claims brought in federal court pursuant to diversity jurisdiction. As Tru-Line did not dispute that it was an unregistered contractor, Judge Sedwick stated that Tru-Line was barred from suing on the contract it entered into with USF & E.
In a separate order from chambers, Judge Sedwick granted USF & E Rule 11 sanctions in the sum of reasonable attorney's fees, expenses, and costs. He found that Tru-Line filed an "utterly baseless" claim under the Miller Act. He also found that the lack of *153 reasonable inquiry made by Tru-Line supported a finding of frivolousness and warranted the imposition of sanctions.

C. The Superior Court Lawsuit
In October 1998 Tru-Line filed suit against USF & E in superior court in Anchorage alleging fraud, negligent misrepresentation, and conversion. USF & E moved for summary judgment based on res judicata. Tru-Line opposed the motion, alleging that the merits of Tru-Line's federal claim were never reached as Tru-Line's complaint was dismissed because it was not a registered Alaska contractor. The state complaint concerned fraud and conversion claims that, according to Tru-Line, could not have been part of its federal complaint as it had no indication that it had been purposefully misled and defrauded by USF & E.
The superior court granted USF & E's motion for summary judgment. USF & E then filed a motion for attorney's fees and sanctions against Tru-Line and its legal counsel, pursuant to Alaska Rules of Civil Procedure 11, 68, 82, and 95. The court, finding that Tru-Line had no reasonable basis in fact to file a complaint on an action deemed by the federal court to be baseless and frivolous, granted USF & E's motion for attorney's fees and sanctions. For violations of Alaska Rules 11 and 95, the court granted USF & E three times its actual costs and attorney's fees to be paid by Tru-Line and its counsel, Jody Sutherland and Craig Holley, jointly and severally. A motion for reconsideration by Tru-Line and its counsels was denied and those parties now appeal to this court.

III. STANDARD OF REVIEW
A superior court's order granting a motion for summary judgment is reviewed de novo.[5] We will affirm a grant of summary judgment if there are no genuine issues of material fact and if the moving party is entitled to summary judgment as a matter of law.[6] The question of whether res judicata applies is a question of law, which we review de novo.[7]

IV. DISCUSSION

A. As the Federal Court Found that It Did Not Have Subject Matter Jurisdiction over Tru-Line's Claim, the Superior Court Erred in Granting Summary Judgment to USF & E.

1. Res judicata generally
Res judicata is a judicial doctrine that has as " `its primary objective claim preclusion or judicial finality.' "[8] Under this doctrine, " `a judgment in a prior action bars a subsequent action if (1) the prior judgment was a final judgment on the merits, (2) a court of competent jurisdiction rendered the prior judgment, and (3) the same cause of action and same parties or their privies were involved in both suits.' "[9]Res judicata implements the "generally recognized public policy that there must be some end to litigation and that when one appears in court to present his case, is fully heard, and the contested issue is decided against him, he may not later renew the litigation in another court."[10]
Tru-Line stipulates for the purposes of this appeal that the federal court entered a final judgment, that the previous case involved the same parties, and that the new claims arose out of the same transaction as the claims in the federal suit. But it argues that res judicata does not apply because the federal court judgment was not "on the merits."


*154 2. The federal court judgment was not "on the merits."

a. Federal question jurisdiction
For a court to exercise federal question jurisdiction, a case must arise under the United States Constitution, the laws of the United States, or treaties made under their authority.[11] The claim arising under federal law must also be substantial; that is, there must be legal substance to the position that the plaintiff is promoting.[12] If the federal claim that is the basis for jurisdiction is obviously without merit or is wholly frivolous, the federal court must dismiss for a lack of jurisdiction.[13] However, "if there is any foundation of plausibility to the claim[,] federal jurisdiction exists."[14] There is no question that a dismissal that results because there is no substantial federal question is a jurisdictional dismissal: " `[I]t remains the federal rule, and needs no reexamination here.'"[15]
In his order granting summary judgment to USF & E, Judge Sedwick found that the Miller Act could not serve as a basis for the district court to exercise jurisdiction. The court based its findings on the fact that the bond obtained by USF & E did not meet the criteria established to be a Miller Act bond; that even if it had been a Miller Act bond, Tru-Line sued the sub-sub-sub-contractor, not the prime contractor; and that even if it had sued the proper party, Tru-Line was too far removed from the prime contractor to sue under the Miller Act. As the court found that Tru-Line's Miller Act claim was not a substantial claim upon which it could exercise federal question jurisdiction, the district court could not exercise pendant jurisdiction over Tru-Line's common law contract claims.
The resolution of the Miller Act claim rested on jurisdictional grounds even though these findings were made in an order of summary judgment. Although the decision may be styled a summary judgment, it "should not gain increased preclusive effects because of the label chosen."[16] As such, a determination of whether the grant of summary judgment as to the federal question was "on the merits" should be looked at in the context of a dismissal for lack of jurisdiction. Such dismissals are not "on the merits."[17]

b. Diversity jurisdiction
Diversity jurisdiction extends to controversies between citizens of different states.[18] Generally, there is a presumption against diversity jurisdiction unless diversity jurisdiction is properly asserted in the pleadings.[19] This presumption places the burden of proof on the party asserting jurisdiction, the sufficiency of which may be raised by the parties or sua sponte by the court at any time.[20] However, a court's discretion to dismiss for lack of subject matter jurisdiction, *155 when the plaintiff could have pled diversity jurisdiction and such jurisdiction in fact exists, should be used sparingly.[21] Jurisdiction may be sustained on the basis of a statute not relied on or alleged in the pleadings.[22] As such, a court may sustain jurisdiction, even if defectively pled, when a proper basis for jurisdiction exists upon review of the entire complaint.[23]
Diversity jurisdiction was not properly pled in district court. The first complaint merely alleged jurisdiction under the Miller Act. In its amended complaint, Tru-Line attempted to allege diversity jurisdiction. Tru-Line is a California corporation and USF & E is an Alaska corporation. These facts were disclosed during oral argument on the summary judgment motion. During that argument, Judge Sedwick allowed Tru-Line to withdraw its defective amended complaint and granted it leave to file another amended complaint, one that would properly allege diversity jurisdiction. Tru-Line, though, never filed an amended complaint properly asserting diversity jurisdiction.
In his order, Judge Sedwick discussed Tru-Line's state law contract claims. He did not, however, state that he was exercising diversity jurisdiction. Rather, he mentioned diversity jurisdiction in a footnote stating that "[t]he Alaska Contractor Registration law is substantive in nature and therefore, applicable to Tru-Line's contract claims brought in federal court pursuant to diversity jurisdiction."
Judge Sedwick's discussion of Tru-Line's state law contract claims did not constitute a final judgment "on the merits." Having given Tru-Line the opportunity to file an amended complaint properly alleging diversity jurisdiction, and Tru-Line having failed to do so, Judge Sedwick's opinion acted only as an advisory opinion on the futility of such action. As Tru-Line did not have a valid claim under the Contractor Registration Act, Judge Sedwick stated, it was unable to sue on the contract it entered into with USF & E. As Judge Sedwick's discussion of the state law claims was advisory and not a judgment on those claims, it is no bar to Tru-Line filing a suit in state court on the contract. Summary judgment in favor of USF & E, therefore, should not have been granted.

B. Because It Was Error To Grant Summary Judgment, the Award of Treble Fees and Costs Is Vacated.
The superior court awarded USF & E treble fees and costs. We need not reach the propriety of this sanction. Because summary judgment should not have been granted, the award of fees and costs must be vacated.

V. CONCLUSION
Because the federal court judgment was not "on the merits," Tru-Line's state court case was not barred by res judicata. The superior court's grant of summary judgment is therefore REVERSED, the award of attorney's fees is vacated, and the case is REMANDED to the superior court for further proceedings on Tru-Line's state law claims.
NOTES
[1]  40 U.S.C. §§ 270a-f (2001). The Miller Act requires the prime contractor on a federal construction project to furnish a payment bond to insure payment to those who have a direct contractual relationship with either the prime contractor or a subcontractor. United States v. Aetna Cas. & Sur. Co., 981 F.2d 448, 450 (9th Cir.1992).
[2]  AS 08.18.151 provides:

A person acting in the capacity of a contractor may not bring an action in a court of this state for the collection of compensation for the performance of work or for breach of a contract for which registration is required under this chapter without alleging and proving that the contractor was a registered contractor at the time of contracting for the performance of the work.
[3]  After taking the matter under advisement and indicating that his practice was to provide a written order explaining his rulings, Judge Sedwick stated: "It does seem to me apparent that there's ... clearly no claim based upon the Miller Act here. This is not a Miller Act bond and a... sub-sub-sub-sub cannot make such a claim, and it's been known for many, many years that... that's not proper."
[4]  Judge Sedwick stated: "I will consider the other matters with respect to the state law issues. I'm not ruling at this time. It does appear to me probable that there's no way this case can be brought into federal court, in view of the substantive state law requiring contractor registration, but I will look at the cases [cited by counsel]."
[5]  White v. State, Dep't of Natural Res., 14 P.3d 956, 959 (Alaska 2000).
[6]  Calhoun v. State, Dep't of Transp. & Pub. Facilities, 857 P.2d 1191, 1193 (Alaska 1993).
[7]  Renwick v. State, Bd. of Marine Pilots, 971 P.2d 631, 633 (Alaska 1999).
[8]  Engebreth v. Moore, 567 P.2d 305, 307 (Alaska 1977) (quoting Drickersen v. Drickersen, 546 P.2d 162, 169 (Alaska 1976)).
[9]  White, 14 P.3d at 959 (quoting Tope v. Christianson, 959 P.2d 1240, 1243 (Alaska 1998)).
[10]  DeNardo v. State, 740 P.2d 453, 455 (Alaska 1987) (internal quotes omitted).
[11]  U.S. CONST., art. III, § 2
[12]  See, e.g., United Mine Workers of America v. Gibbs, 383 U.S. 715, 725, 86 S.Ct. 1130, 16 L.Ed.2d 218 (1966); 13B CHARLES ALAN WRIGHT, ARTHUR R. MILLER, & EDWARD H. COOPER, FEDERAL PRACTICE AND PROCEDURE § 3564, at 66-67 (2d ed.1984) [hereinafter WRIGHT].
[13]  See, e.g., Montana Catholic Missions v. Missoula County, 200 U.S. 118, 130, 26 S.Ct. 197, 50 L.Ed. 398 (1906); Mainelli v. Providence Journal Co., 312 F.2d 3, 5-6 (1st Cir.1962); 13B WRIGHT, supra note 12, § 3564.
[14]  13B WRIGHT, supra note 12, § 3564 at 71; see, e.g., Southpark Square Ltd. v. City of Jackson, Miss., 565 F.2d 338, 342-43 (5th Cir.1977).
[15]  13B WRIGHT, supra note 12, § 3564 at 73 (quoting Hagans v. Lavine, 415 U.S. 528, 538, 94 S.Ct. 1372, 39 L.Ed.2d 577 (1974)).
[16]  18 WRIGHT, supra note 12, § 4444, at 392 (citing Wright Mach. Corp. v. Seaman-Andwall Corp., 364 Mass. 683, 307 N.E.2d 826, 833 (1974)).
[17]  See e.g., In re Matter of Pacific Marine Ins. Co. of Alaska in Liquidation, 877 P.2d 264, 267 n. 2 (Alaska 1994); Ostrow v. Higgins, 722 P.2d 936, 938 (Alaska 1986); Moran v. Poland, 494 P.2d 814, 816 (Alaska 1972).
[18]  U.S. CONST., art. III, § 2.
[19]  See Naartex Consulting Corp. v. Watt, 722 F.2d 779, 792 (D.C.Cir.1983).
[20]  See Rice v. Rice Found., 610 F.2d 471, 474 (7th Cir.1979).
[21]  Hoefferle Truck Sales, Inc. v. Divco-Wayne Corp., 523 F.2d 543, 549 (7th Cir.1975).
[22]  May v. Supreme Court of Colorado, 508 F.2d 136, 137 (10th Cir.1974).
[23]  Van Hoose v. Williams, 496 F.Supp. 947, 948 (E.D.Ky.1980).
