(Gson gson, TypeToken<T> type)
| 185 | private volatile boolean isFirstCall = true; |
| 186 | |
| 187 | @Override |
| 188 | public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { |
| 189 | if (isFirstCall) { |
| 190 | isFirstCall = false; |
| 191 | |
| 192 | class="cm">// Create a separate thread which requests an adapter for the same type |
| 193 | class="cm">// This will cause this factory to return a different adapter instance than |
| 194 | class="cm">// the one it is currently creating |
| 195 | Thread thread = |
| 196 | new Thread() { |
| 197 | @Override |
| 198 | public void run() { |
| 199 | threadAdapter.set(gson.getAdapter(requestedType)); |
| 200 | } |
| 201 | }; |
| 202 | thread.start(); |
| 203 | try { |
| 204 | thread.join(); |
| 205 | } catch (InterruptedException e) { |
| 206 | throw new RuntimeException(e); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | class="cm">// Create a new dummy adapter instance |
| 211 | adapterInstancesCreated.incrementAndGet(); |
| 212 | return new DummyAdapter<>(); |
| 213 | } |
| 214 | }) |
| 215 | .create(); |
| 216 |
nothing calls this directly
no test coverage detected