41 lines
1.2 KiB
Plaintext
41 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
When an SWT ``++Image++`` accesses a file directly, it holds the file handle for the life of the image. Do this many times, and the OS may run out of available file handles. At minimum, SWT ``++Image++``s which directly access files should not be ``++static++``. At best, they should access their files through ``++ImageDescriptors++``, which do not hold open file handles.
|
|
|
|
|
|
This rule looks for ``++org.eclipse.swt.graphics.Image++``s which both directly access a file on the file path and are ``++static++``.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
import org.eclipse.swt.graphics.Image;
|
|
|
|
public class MyView {
|
|
static Image myImage = new Image("path/to/file.png"); // Noncompliant
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
import org.eclipse.swt.graphics.Image;
|
|
import org.eclipse.jface.resource.ImageDescriptor;
|
|
|
|
public class MyView {
|
|
static ImageDescription myDescriptor = ImageDescriptor.createFromFile("path/to/file.png"); // Doesn't hold file handle open
|
|
Image myImage = myDescriptor.getImage();
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|