apache / apache/netbeans

class javax.swing.DebugGraphics cannot be cast to class java.awt.Graphics2D

Open
#5,408 1 comment 0 reactions 0 assignees View on GitHub
debugger Java kind:bug UI
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 16

### What happened

(Copied from the jira issues site after confirming it is still broken in Netbeans 16)
A various number of Windowing components (such as ColorUtil) expect the input graphics to be a `Graphics2D`, which is not the case when `JComponent.setDebugGraphicsOptions​` was set with a non-zero value. This makes it difficult to debug graphical issues.
This, of course, wouldn't be an issue if https://bugs.openjdk.java.net/browse/JDK-4262543 was resolved instead of left hanging, but we are not expecting them to fix that any time soon. The code location given is not the only place where it is assumed.

### How to reproduce

(built at about https://github.com/apache/netbeans/pull/5299/commits/4f52c498989c58b2d568f489fc49b1bfcd5a4400)
Start Netbeans
Put a method breakpoint on `JComponent._paintImmediately`
Evaluate the expression `this.setDebugGraphicsOptions(1);`
You see the exception in the output log when you click on basically anything.

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Mac/Windows. Probably Linux as well

### JDK

OpenJDK Runtime Environment Temurin-19.0.1+10 (build 19.0.1+10)

### Apache NetBeans packaging

Own source build

### Anything else

I discovered this while trying to debug a Netbeans platform application. It was a pain.

### Are you willing to submit a pull request?

No

### Code of Conduct

Yes

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure by starting NetBeans, breaking on JComponent._paintImmediately, and evaluating this.setDebugGraphicsOptions(1). Then inspect the Windowing components mentioned in the report, including ColorUtil, and locate the Graphics2D assumptions; done means clicking components with debug graphics enabled no longer produces the class-cast exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.