Skip to content

I20230419-1800

@SyntevoAlex SyntevoAlex tagged this 19 Apr 17:06
Here's how Text.scrollClipViewToPoint arrives when it causes NPE
  at org.eclipse.swt.widgets.Scrollable.scrollClipViewToPoint(Scrollable.java:347)
  at org.eclipse.swt.widgets.Display.windowProc(Display.java:6754)
  <native to java>
  AppKit`-[NSClipView _scrollTo:animateScroll:flashScrollerKnobs:] + 799
  AppKit`__45-[NSClipView _reflectDocumentViewFrameChange]_block_invoke + 38
  AppKit`-[NSClipView _reflectDocumentViewFrameChange] + 747
  AppKit`-[NSView _postFrameChangeNotification] + 82
  AppKit`-[NSView setPostsFrameChangedNotifications:] + 89
  AppKit`-[NSTextView(NSPrivate) _setWatchingSuperviewClipView:] + 495
  AppKit`-[NSTextView(NSPrivate) _setSuperview:] + 90
  AppKit`-[NSView addSubview:] + 145
  AppKit`-[NSClipView setDocumentView:] + 547
  AppKit`-[NSScrollView setDocumentView:] + 70
  <native to java>
  at org.eclipse.swt.internal.cocoa.NSScrollView.setDocumentView(NSScrollView.java:91)
  at org.eclipse.swt.widgets.Scrollable.setZOrder(Scrollable.java:396)
  at org.eclipse.swt.widgets.Control.createWidget(Control.java:1041)
  at org.eclipse.swt.widgets.Scrollable.createWidget(Scrollable.java:167)
  at org.eclipse.swt.widgets.Text.createWidget(Text.java:596)
  at org.eclipse.swt.widgets.Control.<init>(Control.java:126)
  at org.eclipse.swt.widgets.Scrollable.<init>(Scrollable.java:76)
  at org.eclipse.swt.widgets.Text.<init>(Text.java:140)

And here's how Text receives its this.view.window() just a bit later:
  AppKit`-[NSView _setWindow:] + 876
  AppKit`-[NSTextView(NSPrivate) _setWindow:] + 263
  AppKit`-[NSView addSubview:] + 172
  <the rest is same as above>

This resulted in NPE like this
  java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.internal.cocoa.NSWindow.contentView()" because "window" is null
  at org.eclipse.swt.widgets.Control.calculateVisibleRegion(Control.java:775)
  at org.eclipse.swt.widgets.Control.getVisibleRegion(Control.java:2060)
  at org.eclipse.swt.widgets.Control.isObscured(Control.java:2341)
  at org.eclipse.swt.widgets.Scrollable.scrollClipViewToPoint(Scrollable.java:347)
  at org.eclipse.swt.widgets.Display.windowProc(Display.java:6754)
  at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
  at org.eclipse.swt.internal.cocoa.NSScrollView.setDocumentView(NSScrollView.java:91)
  at org.eclipse.swt.widgets.Scrollable.setZOrder(Scrollable.java:396)
  at org.eclipse.swt.widgets.Control.createWidget(Control.java:1026)
  at org.eclipse.swt.widgets.Scrollable.createWidget(Scrollable.java:167)
  at org.eclipse.swt.widgets.Text.createWidget(Text.java:596)
  at org.eclipse.swt.widgets.Control.(Control.java:126)
  at org.eclipse.swt.widgets.Scrollable.(Scrollable.java:76)
  at org.eclipse.swt.widgets.Text.(Text.java:140)
  <...>

Results with attached unit test before the patch:
  macOS 12    - reproducible with font=10
  macOS 11    - reproducible with font=10
  macOS 10.15 - reproducible with font=10
  macOS 10.14 - reproducible with font=10
  macOS 10.13 - NOT reproducible, with fonts in range 1...100

Fixes #472
Fixes https://bugs.eclipse.org/bugs/show_bug.cgi?id=559198

Helped-By: https://github.com/Phillipus
Helped-By: https://github.com/sratz
Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
Assets 2
Loading