In an era of increasing debate over the right of the press to protect news sources, a television reporter here has taken the unprecedented step of testifying about private conversations with a murder suspect after a judge told him he did not have to.

The action by David Lopez, 33, a reporter for CBS-owned KNXT-TV, has dismayed many journalists and surprised prosecutors, but received warm support from the general public.

Although Lopez appears to have set no legal precedent by testifying, many journalists say he may have discouraged news sources from talking to reporters in the future and encouraged prosecutors to coax cooperation from reporters holding important evidence.

Lopez' decision to testify in the grisly case involving the murders of 21 young men and boys came shortly after the reporter had won what lawyers consider an important decision upholding California's shield law protecting news sources and reporters even in murder cases.

Lopez, who six months ago had reported a sensational confession by accused "freeway killer" William G. Bonin to the 21 murders, said in an interview he had wavered for months between what he saw as his responsibilities as a journalist and as a citizen.

Although the prosecution appeared to have a good case against Bonin, including testimony from two accomplices who allegedly helped in the murders and the dumping of the bodies near freeways, Lopez says, "somewhere in the back of my mind, I did keep saying, what happens if . . . ?"

Lopez said he remembered, from his notes, Bonin's answer when he asked what Bonin would be doing if he was not in jail: "I'd still be killing. I couldn't stop killing. It got easier each time."

Since Lopez testified Monday, a Los Angeles police spokesman called him a hero and strangers have been stopping him to thank him. A card from the family of one of the murder victims "had the words 'thank you' written on it about 100 times."

The television reporter, a Los Angeles native who began as a sportswriter on a small daily when he was 18, has been sharply criticized, however, by another journalist who heard incriminating statements from Bonin but refused to testify at the trial. "I hope it's not a precedent," said Timothy Alger, a 26-year-old reporter for the Orange County Register. "I have never heard of any other reporter doing what Mr. Lopez has done."

An official of the Reporters Committee for Freedom of the Press, based in Washington, said committee records indicated Lopez's actions were unprecedented.

William Farr, a Los Angeles Times reporter who spent 47 days in jail for refusing to disclose a source for a story on the Charles Manson murder trial, said "I appreciate the dilemma that Lopez felt, but I still disagree . . . . It's easy to say that you have a responsibility as a citizen, but the problem is we often get confidential information because we are reporters, and not average citizens . . . . You have to be concerned about other news sources who won't come to reporters now."

The seeds of Lopez' dilemma were planted Jan. 9, when he interviewed Bonin, a 34-year-old truck driver with a record of sex crimes against teen-age boys, in the attorney's room of the Los Angeles County jail.

Bonin, who Lopez said "loves to talk," confessed to 21 murders, the reporter said, but with the understanding Lopez would not broadcast what he had heard until Bonin was guaranteed by prosecutors that they would not ask for the death penalty, a guarantee which never came.

Bonin, in turn, promised not to repeat his confession to other reporters, Lopez said.

Bonin talked to Alger, however, and Alger wrote three articles which, although they did not report a confession, quoted Bonin as saying "I knew I was on a destructive course" and that he and an accomplice "weren't leaving any evidence behind."

Lopez said he thought Bonin had violated their agreement by talking to Alger, a statement Alger and other reporters said shows Lopez takes a reporter's promise of confidentiality far too lightly.

In June, after Lopez heard that Bonin was trying to sell his story to a movie producer, he and his superiors at the station decided to broadcast a short account of Bonin's confession, including some but not all of the details of the sex slayings Bonin had related.

Prosecutors tried to subpoena Lopez' and Alger's notes and force them to testify, but Superior Court Judge William B. Keene ruled that the California shield law protected them.

Up to that point, Lopez said, he was fairly sure he did not want to testify. "I thought it was a clear case of them trying to force me to reveal things that I felt they had no right to know," Lopez said. Lopez said police and parents of the victims had made clear their desire for him to testify, but "I kept thinking, they've got enough."

"I am not a deeply religious person," Lopez said. "But I prayed a lot the whole time since January." When the final arguments at the trial were suddenly postponed because Bonin was injured in what appeared to be a jailhouse fight, "it made me realize that someone greater than me was trying to tell me something," Lopez said, and at the last minute he told prosecutors he would testify.

Lopez' testimony added some details to what the jury had previously heard about the 12 murders in Los Angeles they are considering, but more importantly it linked Bonin to all 21 murders in southern California for which he is suspected.

Bonin did not testify in the trial, in which final arguments began today.

Some editors have accused Lopez of grandstanding. "In some way, I'm personally ashamed of the way I behaved in this thing," Lopez said, speaking of his hesitation to come forward. "But I feel good about it now."