View Javadoc
1   /*
2    * SPDX-License-Identifier: Apache-2.0
3    * See LICENSE file for details.
4    *
5    * Copyright 2012-2026 hazendaz
6    *
7    * Portions of initial baseline code (getter/setter test) by Rob Dawson (CodeBox)
8    */
9   package com.codebox.bean;
10  
11  import java.io.Serializable;
12  
13  /**
14   * The Class SerializableWithThreadFieldBean.
15   *
16   * <p>
17   * A {@link Serializable} bean that holds a non-serializable {@link Thread} field initialised in the constructor.
18   * Serializing an instance always throws {@link java.io.NotSerializableException} (a subtype of
19   * {@link java.io.IOException}), which exercises the IOException catch block in
20   * {@code JavaBeanTesterWorker.canSerialize()}.
21   */
22  public class SerializableWithThreadFieldBean implements Serializable {
23  
24      /** The Constant serialVersionUID. */
25      private static final long serialVersionUID = 1L;
26  
27      /** The thread - NOT serializable; always non-null. */
28      @SuppressWarnings("java:S1948")
29      private Thread thread = Thread.currentThread();
30  
31      /**
32       * Gets the thread.
33       *
34       * @return the thread
35       */
36      public Thread getThread() {
37          return this.thread;
38      }
39  
40      /**
41       * Sets the thread.
42       *
43       * @param thread
44       *            the thread
45       */
46      public void setThread(final Thread thread) {
47          this.thread = thread;
48      }
49  
50  }