
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
44 lines
1.3 KiB
Plaintext
44 lines
1.3 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)
|
|
|
|
=== Message
|
|
|
|
Either remove the "static" modifier or use an "ImageDescriptor" to feed this "Image".
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|