EtashGuha commited on
Commit
2f33c9f
·
verified ·
1 Parent(s): 8023342

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. inferredbugs-0033/instruction.md +1 -16
  2. inferredbugs-0200/instruction.md +1 -16
  3. inferredbugs-0201/instruction.md +1 -16
  4. inferredbugs-0209/instruction.md +1 -16
  5. inferredbugs-0456/instruction.md +1 -16
  6. inferredbugs-0665/instruction.md +1 -16
  7. inferredbugs-0690/instruction.md +1 -16
  8. inferredbugs-0699/instruction.md +92 -0
  9. inferredbugs-0807/instruction.md +1 -16
  10. inferredbugs-10110/instruction.md +150 -0
  11. inferredbugs-10119/instruction.md +1 -16
  12. inferredbugs-10322/instruction.md +1 -16
  13. inferredbugs-10580/instruction.md +1 -16
  14. inferredbugs-10588/instruction.md +1 -16
  15. inferredbugs-10589/instruction.md +1 -16
  16. inferredbugs-10746/instruction.md +1 -16
  17. inferredbugs-10925/instruction.md +2467 -0
  18. inferredbugs-11006/instruction.md +1 -16
  19. inferredbugs-11036/instruction.md +1 -16
  20. inferredbugs-1114/instruction.md +1 -16
  21. inferredbugs-1326/instruction.md +1 -16
  22. inferredbugs-1570/instruction.md +1 -16
  23. inferredbugs-1579/instruction.md +570 -0
  24. inferredbugs-1742/instruction.md +141 -0
  25. inferredbugs-1921/instruction.md +1 -16
  26. inferredbugs-1928/instruction.md +1 -16
  27. inferredbugs-2308/instruction.md +1 -16
  28. inferredbugs-2338/instruction.md +1 -16
  29. inferredbugs-2557/instruction.md +1 -16
  30. inferredbugs-2764/instruction.md +1 -16
  31. inferredbugs-2765/instruction.md +1 -16
  32. inferredbugs-2791/instruction.md +285 -0
  33. inferredbugs-2906/instruction.md +167 -0
  34. inferredbugs-2936/instruction.md +1 -16
  35. inferredbugs-3015/instruction.md +1 -16
  36. inferredbugs-3227/instruction.md +1 -16
  37. inferredbugs-3471/instruction.md +1 -16
  38. inferredbugs-3478/instruction.md +1 -16
  39. inferredbugs-3484/instruction.md +1 -16
  40. inferredbugs-3485/instruction.md +1 -16
  41. inferredbugs-3643/instruction.md +1 -16
  42. inferredbugs-3820/instruction.md +1 -16
  43. inferredbugs-3829/instruction.md +1 -16
  44. inferredbugs-4002/instruction.md +1 -16
  45. inferredbugs-4230/instruction.md +1 -16
  46. inferredbugs-4239/instruction.md +1 -16
  47. inferredbugs-4466/instruction.md +1 -16
  48. inferredbugs-4493/instruction.md +1 -16
  49. inferredbugs-4654/instruction.md +1 -16
  50. inferredbugs-4699/instruction.md +1 -16
inferredbugs-0033/instruction.md CHANGED
@@ -255,19 +255,4 @@ Null Dereference
255
 
256
  ## Task
257
 
258
- Analyze the bug information provided above. Your task is to:
259
-
260
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
261
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
262
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
263
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
264
-
265
- ### Analysis Questions:
266
- - What was the specific bug or issue in the original code?
267
- - What scenarios would trigger this bug?
268
- - How does the fix address the root cause?
269
- - Are there any potential edge cases the fix might miss?
270
- - What coding practices could have prevented this bug?
271
- - Are there alternative ways to implement the fix?
272
-
273
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
255
 
256
  ## Task
257
 
258
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-0200/instruction.md CHANGED
@@ -269,19 +269,4 @@ Null Dereference
269
 
270
  ## Task
271
 
272
- Analyze the bug information provided above. Your task is to:
273
-
274
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
275
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
276
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
277
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
278
-
279
- ### Analysis Questions:
280
- - What was the specific bug or issue in the original code?
281
- - What scenarios would trigger this bug?
282
- - How does the fix address the root cause?
283
- - Are there any potential edge cases the fix might miss?
284
- - What coding practices could have prevented this bug?
285
- - Are there alternative ways to implement the fix?
286
-
287
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
269
 
270
  ## Task
271
 
272
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-0201/instruction.md CHANGED
@@ -266,19 +266,4 @@ Null Dereference
266
 
267
  ## Task
268
 
269
- Analyze the bug information provided above. Your task is to:
270
-
271
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
272
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
273
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
274
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
275
-
276
- ### Analysis Questions:
277
- - What was the specific bug or issue in the original code?
278
- - What scenarios would trigger this bug?
279
- - How does the fix address the root cause?
280
- - Are there any potential edge cases the fix might miss?
281
- - What coding practices could have prevented this bug?
282
- - Are there alternative ways to implement the fix?
283
-
284
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
266
 
267
  ## Task
268
 
269
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-0209/instruction.md CHANGED
@@ -441,19 +441,4 @@ Null Dereference
441
 
442
  ## Task
443
 
444
- Analyze the bug information provided above. Your task is to:
445
-
446
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
447
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
448
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
449
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
450
-
451
- ### Analysis Questions:
452
- - What was the specific bug or issue in the original code?
453
- - What scenarios would trigger this bug?
454
- - How does the fix address the root cause?
455
- - Are there any potential edge cases the fix might miss?
456
- - What coding practices could have prevented this bug?
457
- - Are there alternative ways to implement the fix?
458
-
459
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
441
 
442
  ## Task
443
 
444
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-0456/instruction.md CHANGED
@@ -443,19 +443,4 @@ Dotnet Resource Leak
443
 
444
  ## Task
445
 
446
- Analyze the bug information provided above. Your task is to:
447
-
448
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
449
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
450
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
451
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
452
-
453
- ### Analysis Questions:
454
- - What was the specific bug or issue in the original code?
455
- - What scenarios would trigger this bug?
456
- - How does the fix address the root cause?
457
- - Are there any potential edge cases the fix might miss?
458
- - What coding practices could have prevented this bug?
459
- - Are there alternative ways to implement the fix?
460
-
461
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
443
 
444
  ## Task
445
 
446
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-0665/instruction.md CHANGED
@@ -98,19 +98,4 @@ Dotnet Resource Leak
98
 
99
  ## Task
100
 
101
- Analyze the bug information provided above. Your task is to:
102
-
103
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
104
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
105
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
106
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
107
-
108
- ### Analysis Questions:
109
- - What was the specific bug or issue in the original code?
110
- - What scenarios would trigger this bug?
111
- - How does the fix address the root cause?
112
- - Are there any potential edge cases the fix might miss?
113
- - What coding practices could have prevented this bug?
114
- - Are there alternative ways to implement the fix?
115
-
116
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
98
 
99
  ## Task
100
 
101
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-0690/instruction.md CHANGED
@@ -70,19 +70,4 @@ Dotnet Resource Leak
70
 
71
  ## Task
72
 
73
- Analyze the bug information provided above. Your task is to:
74
-
75
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
76
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
77
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
78
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
79
-
80
- ### Analysis Questions:
81
- - What was the specific bug or issue in the original code?
82
- - What scenarios would trigger this bug?
83
- - How does the fix address the root cause?
84
- - Are there any potential edge cases the fix might miss?
85
- - What coding practices could have prevented this bug?
86
- - Are there alternative ways to implement the fix?
87
-
88
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
70
 
71
  ## Task
72
 
73
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-0699/instruction.md ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # InferredBugs Task - Csharp
2
+
3
+ ## Project Information
4
+
5
+ **Project:** python-language-server
6
+ **Bug ID:** 7
7
+ **Language:** csharp
8
+
9
+ ## Bug Information
10
+
11
+ ### File-Level Changes:
12
+
13
+ **Before (Buggy File):**
14
+ ```csharp
15
+ using System.IO;
16
+ using FluentAssertions;
17
+ using Microsoft.Python.Core.Text;
18
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
19
+ using TestUtilities;
20
+
21
+ namespace Microsoft.Python.Parsing.Tests {
22
+ /// <summary>
23
+ /// Test cases to verify that the tokenizer maintains expected behaviour.
24
+ /// </summary>
25
+ [TestClass]
26
+ public class TokenizerTests {
27
+ public TestContext TestContext { get; set; }
28
+
29
+ [TestInitialize]
30
+ public void TestInitialize() => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}");
31
+
32
+ [TestCleanup]
33
+ public void TestCleanup() => TestEnvironmentImpl.TestCleanup();
34
+
35
+ internal static readonly PythonLanguageVersion[] AllVersions = new[] { PythonLanguageVersion.V26, PythonLanguageVersion.V27, PythonLanguageVersion.V30, PythonLanguageVersion.V31, PythonLanguageVersion.V32, PythonLanguageVersion.V33, PythonLanguageVersion.V34, PythonLanguageVersion.V35, PythonLanguageVersion.V36, PythonLanguageVersion.V37 };
36
+
37
+ [TestMethod, Priority(0)]
38
+ public void AbsoluteTokenizerIndex() {
39
+ foreach (var version in AllVersions) {
40
+ var tokenizer = MakeTokenizer(version, TokenizerOptions.None, "x = 1", new SourceLocation(5, 100, 3));
41
+
42
+ // Read 'x' token
43
+ var tokenInfo = tokenizer.ReadToken();
44
+ tokenizer.TokenSpan.Should().Be(new IndexSpan(5, 1));
45
+ tokenizer.CurrentPosition.Should().BeEquivalentTo(new SourceLocation(6, 100, 4));
46
+
47
+ // Read '=' token
48
+ tokenInfo = tokenizer.ReadToken();
49
+ tokenizer.TokenSpan.Should().Be(new IndexSpan(7, 1));
50
+ tokenizer.CurrentPosition.Should().BeEquivalentTo(new SourceLocation(8, 100, 6));
51
+ }
52
+ }
53
+
54
+ private Tokenizer MakeTokenizer(PythonLanguageVersion version, TokenizerOptions optionSet, string text,
55
+ SourceLocation? initialSourceLocation = null) {
56
+ var tokenizer = new Tokenizer(version, options: optionSet);
57
+
58
+ tokenizer.Initialize(null, new StringReader(text), initialSourceLocation ?? SourceLocation.MinValue);
59
+ return tokenizer;
60
+ }
61
+ }
62
+ }
63
+
64
+ ```
65
+
66
+ ### Bug Type:
67
+ DOTNET_RESOURCE_LEAK
68
+
69
+ ### Qualifier:
70
+ Leaked resource (output of System.IO.StringReader::.ctor() at Line 44) of type System.IO.StringReader in method "Tokenizer TokenizerTests.MakeTokenizer(PythonLanguageVersion,TokenizerOptions,String,Nullable`1<!0>)".
71
+
72
+ ### Severity:
73
+ ERROR
74
+
75
+ ### Procedure:
76
+ Tokenizer TokenizerTests.MakeTokenizer(PythonLanguageVersion,TokenizerOptions,String,Nullable`1<!0>)
77
+
78
+ ### File:
79
+ src/Parsing/Test/TokenizerTest.cs
80
+
81
+ ### Key:
82
+ TokenizerTest.cs|MakeTokenizer|DOTNET_RESOURCE_LEAK
83
+
84
+ ### Hash:
85
+ 43dc3763912e60450bbd61087d22fac0
86
+
87
+ ### Bug Type Hum:
88
+ Dotnet Resource Leak
89
+
90
+ ## Task
91
+
92
+ Fix the bug in the code.
inferredbugs-0807/instruction.md CHANGED
@@ -113,19 +113,4 @@ Uninitialized Value
113
 
114
  ## Task
115
 
116
- Analyze the bug information provided above. Your task is to:
117
-
118
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
119
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
120
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
121
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
122
-
123
- ### Analysis Questions:
124
- - What was the specific bug or issue in the original code?
125
- - What scenarios would trigger this bug?
126
- - How does the fix address the root cause?
127
- - Are there any potential edge cases the fix might miss?
128
- - What coding practices could have prevented this bug?
129
- - Are there alternative ways to implement the fix?
130
-
131
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
113
 
114
  ## Task
115
 
116
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-10110/instruction.md ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # InferredBugs Task - Java
2
+
3
+ ## Project Information
4
+
5
+ **Project:** jadb
6
+ **Bug ID:** 12
7
+ **Language:** java
8
+
9
+ ## Bug Information
10
+
11
+ ### File-Level Changes:
12
+
13
+ **Before (Buggy File):**
14
+ ```java
15
+ package se.vidstige.jadb;
16
+
17
+
18
+ import java.io.IOException;
19
+ import java.net.InetSocketAddress;
20
+ import java.net.Socket;
21
+ import java.util.ArrayList;
22
+ import java.util.List;
23
+
24
+ public class JadbConnection implements ITransportFactory {
25
+
26
+ private final String host;
27
+ private final int port;
28
+
29
+ private static final int DEFAULTPORT = 5037;
30
+
31
+ public JadbConnection() {
32
+ this("localhost", DEFAULTPORT);
33
+ }
34
+
35
+ public JadbConnection(String host, int port) {
36
+ this.host = host;
37
+ this.port = port;
38
+ }
39
+
40
+ public Transport createTransport() throws IOException {
41
+ return new Transport(new Socket(host, port));
42
+ }
43
+
44
+ public String getHostVersion() throws IOException, JadbException {
45
+ Transport main = createTransport();
46
+ main.send("host:version");
47
+ main.verifyResponse();
48
+ String version = main.readString();
49
+ main.close();
50
+ return version;
51
+ }
52
+
53
+ public InetSocketAddress connectToTcpDevice(InetSocketAddress inetSocketAddress)
54
+ throws IOException, JadbException, ConnectionToRemoteDeviceException {
55
+ Transport transport = createTransport();
56
+ try {
57
+ return new HostConnectToRemoteTcpDevice(transport).connect(inetSocketAddress);
58
+ } finally {
59
+ transport.close();
60
+ }
61
+ }
62
+
63
+ public InetSocketAddress disconnectFromTcpDevice(InetSocketAddress tcpAddressEntity)
64
+ throws IOException, JadbException, ConnectionToRemoteDeviceException {
65
+ Transport transport = createTransport();
66
+ try {
67
+ return new HostDisconnectFromRemoteTcpDevice(transport).disconnect(tcpAddressEntity);
68
+ } finally {
69
+ transport.close();
70
+ }
71
+ }
72
+
73
+ public List<JadbDevice> getDevices() throws IOException, JadbException {
74
+ Transport devices = createTransport();
75
+ devices.send("host:devices");
76
+ devices.verifyResponse();
77
+ String body = devices.readString();
78
+ devices.close();
79
+ return parseDevices(body);
80
+ }
81
+
82
+ public DeviceWatcher createDeviceWatcher(DeviceDetectionListener listener) throws IOException, JadbException {
83
+ Transport transport = createTransport();
84
+ transport.send("host:track-devices");
85
+ transport.verifyResponse();
86
+ return new DeviceWatcher(transport, listener, this);
87
+ }
88
+
89
+ public List<JadbDevice> parseDevices(String body) {
90
+ String[] lines = body.split("\n");
91
+ ArrayList<JadbDevice> devices = new ArrayList<>(lines.length);
92
+ for (String line : lines) {
93
+ String[] parts = line.split("\t");
94
+ if (parts.length > 1) {
95
+ devices.add(new JadbDevice(parts[0], this)); // parts[1] is type
96
+ }
97
+ }
98
+ return devices;
99
+ }
100
+
101
+ public JadbDevice getAnyDevice() {
102
+ return JadbDevice.createAny(this);
103
+ }
104
+ }
105
+
106
+ ```
107
+
108
+ ### Bug Class:
109
+ PROVER
110
+
111
+ ### Kind:
112
+ ERROR
113
+
114
+ ### Bug Type:
115
+ RESOURCE_LEAK
116
+
117
+ ### Qualifier:
118
+ resource of type `se.vidstige.jadb.Transport` acquired to `devices` by call to `createTransport()` at line 60 is not released after line 65.
119
+ **Note**: potential exception at line 61
120
+
121
+ ### Severity:
122
+ HIGH
123
+
124
+ ### Visibility:
125
+ user
126
+
127
+ ### Procedure:
128
+ List JadbConnection.getDevices()
129
+
130
+ ### Procedure Id:
131
+ se.vidstige.jadb.JadbConnection.getDevices():java.util.List.57bed4e3693000d7b8ab7ac2a7b70518
132
+
133
+ ### File:
134
+ src/se/vidstige/jadb/JadbConnection.java
135
+
136
+ ### Key:
137
+ JadbConnection.java|getDevices|RESOURCE_LEAK
138
+
139
+ ### Node Key:
140
+ 48815eab4c26cee962db00712b67bbd0
141
+
142
+ ### Hash:
143
+ 3e4fa90d088841029c9931270a4d8892
144
+
145
+ ### Bug Type Hum:
146
+ Resource Leak
147
+
148
+ ## Task
149
+
150
+ Fix the bug in the code.
inferredbugs-10119/instruction.md CHANGED
@@ -146,19 +146,4 @@ Resource Leak
146
 
147
  ## Task
148
 
149
- Analyze the bug information provided above. Your task is to:
150
-
151
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
152
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
153
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
154
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
155
-
156
- ### Analysis Questions:
157
- - What was the specific bug or issue in the original code?
158
- - What scenarios would trigger this bug?
159
- - How does the fix address the root cause?
160
- - Are there any potential edge cases the fix might miss?
161
- - What coding practices could have prevented this bug?
162
- - Are there alternative ways to implement the fix?
163
-
164
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
146
 
147
  ## Task
148
 
149
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-10322/instruction.md CHANGED
@@ -409,19 +409,4 @@ Interface Not Thread Safe
409
 
410
  ## Task
411
 
412
- Analyze the bug information provided above. Your task is to:
413
-
414
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
415
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
416
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
417
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
418
-
419
- ### Analysis Questions:
420
- - What was the specific bug or issue in the original code?
421
- - What scenarios would trigger this bug?
422
- - How does the fix address the root cause?
423
- - Are there any potential edge cases the fix might miss?
424
- - What coding practices could have prevented this bug?
425
- - Are there alternative ways to implement the fix?
426
-
427
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
409
 
410
  ## Task
411
 
412
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-10580/instruction.md CHANGED
@@ -276,19 +276,4 @@ Null Dereference
276
 
277
  ## Task
278
 
279
- Analyze the bug information provided above. Your task is to:
280
-
281
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
282
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
283
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
284
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
285
-
286
- ### Analysis Questions:
287
- - What was the specific bug or issue in the original code?
288
- - What scenarios would trigger this bug?
289
- - How does the fix address the root cause?
290
- - Are there any potential edge cases the fix might miss?
291
- - What coding practices could have prevented this bug?
292
- - Are there alternative ways to implement the fix?
293
-
294
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
276
 
277
  ## Task
278
 
279
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-10588/instruction.md CHANGED
@@ -99,19 +99,4 @@ Resource Leak
99
 
100
  ## Task
101
 
102
- Analyze the bug information provided above. Your task is to:
103
-
104
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
105
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
106
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
107
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
108
-
109
- ### Analysis Questions:
110
- - What was the specific bug or issue in the original code?
111
- - What scenarios would trigger this bug?
112
- - How does the fix address the root cause?
113
- - Are there any potential edge cases the fix might miss?
114
- - What coding practices could have prevented this bug?
115
- - Are there alternative ways to implement the fix?
116
-
117
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
99
 
100
  ## Task
101
 
102
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-10589/instruction.md CHANGED
@@ -204,19 +204,4 @@ Null Dereference
204
 
205
  ## Task
206
 
207
- Analyze the bug information provided above. Your task is to:
208
-
209
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
210
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
211
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
212
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
213
-
214
- ### Analysis Questions:
215
- - What was the specific bug or issue in the original code?
216
- - What scenarios would trigger this bug?
217
- - How does the fix address the root cause?
218
- - Are there any potential edge cases the fix might miss?
219
- - What coding practices could have prevented this bug?
220
- - Are there alternative ways to implement the fix?
221
-
222
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
204
 
205
  ## Task
206
 
207
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-10746/instruction.md CHANGED
@@ -235,19 +235,4 @@ Null Dereference
235
 
236
  ## Task
237
 
238
- Analyze the bug information provided above. Your task is to:
239
-
240
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
241
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
242
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
243
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
244
-
245
- ### Analysis Questions:
246
- - What was the specific bug or issue in the original code?
247
- - What scenarios would trigger this bug?
248
- - How does the fix address the root cause?
249
- - Are there any potential edge cases the fix might miss?
250
- - What coding practices could have prevented this bug?
251
- - Are there alternative ways to implement the fix?
252
-
253
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
235
 
236
  ## Task
237
 
238
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-10925/instruction.md ADDED
@@ -0,0 +1,2467 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # InferredBugs Task - Java
2
+
3
+ ## Project Information
4
+
5
+ **Project:** rxjava2-jdbc
6
+ **Bug ID:** 98
7
+ **Language:** java
8
+
9
+ ## Bug Information
10
+
11
+ ### File-Level Changes:
12
+
13
+ **Before (Buggy File):**
14
+ ```java
15
+ package org.davidmoten.rx.jdbc;
16
+
17
+ import static org.junit.Assert.assertEquals;
18
+ import static org.junit.Assert.assertFalse;
19
+ import static org.junit.Assert.assertNotEquals;
20
+ import static org.junit.Assert.assertTrue;
21
+
22
+ import java.io.ByteArrayInputStream;
23
+ import java.io.ByteArrayOutputStream;
24
+ import java.io.File;
25
+ import java.io.FileNotFoundException;
26
+ import java.io.FileReader;
27
+ import java.io.IOException;
28
+ import java.io.InputStream;
29
+ import java.io.Reader;
30
+ import java.sql.Blob;
31
+ import java.sql.Clob;
32
+ import java.sql.Connection;
33
+ import java.sql.SQLException;
34
+ import java.sql.SQLSyntaxErrorException;
35
+ import java.sql.Time;
36
+ import java.sql.Timestamp;
37
+ import java.time.Instant;
38
+ import java.time.ZoneOffset;
39
+ import java.time.ZonedDateTime;
40
+ import java.util.Arrays;
41
+ import java.util.Calendar;
42
+ import java.util.Date;
43
+ import java.util.GregorianCalendar;
44
+ import java.util.List;
45
+ import java.util.Optional;
46
+ import java.util.concurrent.CopyOnWriteArrayList;
47
+ import java.util.concurrent.CountDownLatch;
48
+ import java.util.concurrent.Executors;
49
+ import java.util.concurrent.TimeUnit;
50
+ import java.util.concurrent.TimeoutException;
51
+ import java.util.concurrent.atomic.AtomicBoolean;
52
+ import java.util.concurrent.atomic.AtomicInteger;
53
+
54
+ import org.apache.log4j.Level;
55
+ import org.apache.log4j.LogManager;
56
+ import org.davidmoten.rx.jdbc.annotations.Column;
57
+ import org.davidmoten.rx.jdbc.annotations.Index;
58
+ import org.davidmoten.rx.jdbc.annotations.Query;
59
+ import org.davidmoten.rx.jdbc.exceptions.AnnotationsNotFoundException;
60
+ import org.davidmoten.rx.jdbc.exceptions.AutomappedInterfaceInaccessibleException;
61
+ import org.davidmoten.rx.jdbc.exceptions.ColumnIndexOutOfRangeException;
62
+ import org.davidmoten.rx.jdbc.exceptions.ColumnNotFoundException;
63
+ import org.davidmoten.rx.jdbc.exceptions.MoreColumnsRequestedThanExistException;
64
+ import org.davidmoten.rx.jdbc.exceptions.NamedParameterFoundButSqlDoesNotHaveNamesException;
65
+ import org.davidmoten.rx.jdbc.exceptions.NamedParameterMissingException;
66
+ import org.davidmoten.rx.jdbc.exceptions.QueryAnnotationMissingException;
67
+ import org.davidmoten.rx.jdbc.pool.DatabaseCreator;
68
+ import org.davidmoten.rx.jdbc.pool.NonBlockingConnectionPool;
69
+ import org.davidmoten.rx.jdbc.pool.Pools;
70
+ import org.davidmoten.rx.jdbc.tuple.Tuple2;
71
+ import org.davidmoten.rx.jdbc.tuple.Tuple3;
72
+ import org.davidmoten.rx.jdbc.tuple.Tuple4;
73
+ import org.davidmoten.rx.jdbc.tuple.Tuple5;
74
+ import org.davidmoten.rx.jdbc.tuple.Tuple6;
75
+ import org.davidmoten.rx.jdbc.tuple.Tuple7;
76
+ import org.davidmoten.rx.jdbc.tuple.TupleN;
77
+ import org.davidmoten.rx.pool.PoolClosedException;
78
+ import org.h2.jdbc.JdbcSQLException;
79
+ import org.hsqldb.jdbc.JDBCBlobFile;
80
+ import org.hsqldb.jdbc.JDBCClobFile;
81
+ import org.junit.Assert;
82
+ import org.junit.FixMethodOrder;
83
+ import org.junit.Ignore;
84
+ import org.junit.Test;
85
+ import org.junit.runners.MethodSorters;
86
+ import org.slf4j.Logger;
87
+ import org.slf4j.LoggerFactory;
88
+
89
+ import com.github.davidmoten.guavamini.Lists;
90
+
91
+ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
92
+ import io.reactivex.Completable;
93
+ import io.reactivex.Flowable;
94
+ import io.reactivex.Observable;
95
+ import io.reactivex.Scheduler;
96
+ import io.reactivex.Single;
97
+ import io.reactivex.functions.Predicate;
98
+ import io.reactivex.schedulers.Schedulers;
99
+ import io.reactivex.schedulers.TestScheduler;
100
+ import io.reactivex.subscribers.TestSubscriber;
101
+
102
+ @FixMethodOrder(MethodSorters.NAME_ASCENDING)
103
+ public class DatabaseTest {
104
+
105
+ private static final long FRED_REGISTERED_TIME = 1442515672690L;
106
+ private static final int NAMES_COUNT_BIG = 5163;
107
+ private static final Logger log = LoggerFactory.getLogger(DatabaseTest.class);
108
+ private static final int TIMEOUT_SECONDS = 2;
109
+
110
+ private static Database db() {
111
+ return DatabaseCreator.create(1);
112
+ }
113
+
114
+ private static Database blocking() {
115
+ return DatabaseCreator.createBlocking();
116
+ }
117
+
118
+ private static Database db(int poolSize) {
119
+ return DatabaseCreator.create(poolSize);
120
+ }
121
+
122
+ private static Database big(int poolSize) {
123
+ return DatabaseCreator.create(poolSize, true, Schedulers.computation());
124
+ }
125
+
126
+ @Test
127
+ public void testSelectUsingQuestionMark() {
128
+ try (Database db = db()) {
129
+ db.select("select score from person where name=?") //
130
+ .parameters("FRED", "JOSEPH") //
131
+ .getAs(Integer.class) //
132
+ .test() //
133
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
134
+ .assertNoErrors() //
135
+ .assertValues(21, 34) //
136
+ .assertComplete();
137
+ }
138
+ }
139
+
140
+ @Test
141
+ public void testSelectUsingNamedParameterList() {
142
+ try (Database db = db()) {
143
+ db.select("select score from person where name=:name") //
144
+ .parameters(Parameter.named("name", "FRED").value("JOSEPH").list()) //
145
+ .getAs(Integer.class) //
146
+ .test() //
147
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
148
+ .assertNoErrors() //
149
+ .assertValues(21, 34) //
150
+ .assertComplete();
151
+ }
152
+ }
153
+
154
+ @Test
155
+ public void testSelectUsingQuestionMarkFlowableParameters() {
156
+ try (Database db = db()) {
157
+ db.select("select score from person where name=?") //
158
+ .parameterStream(Flowable.just("FRED", "JOSEPH")) //
159
+ .getAs(Integer.class) //
160
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
161
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
162
+ .assertNoErrors() //
163
+ .assertValues(21, 34) //
164
+ .assertComplete();
165
+ }
166
+ }
167
+
168
+ @Test
169
+ public void testSelectUsingQuestionMarkFlowableParametersInLists() {
170
+ try (Database db = db()) {
171
+ db.select("select score from person where name=?") //
172
+ .parameterListStream(
173
+ Flowable.just(Arrays.asList("FRED"), Arrays.asList("JOSEPH"))) //
174
+ .getAs(Integer.class) //
175
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
176
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
177
+ .assertNoErrors() //
178
+ .assertValues(21, 34) //
179
+ .assertComplete();
180
+ }
181
+ }
182
+
183
+ @Test
184
+ public void testDrivingSelectWithoutParametersUsingParameterStream() {
185
+ try (Database db = db()) {
186
+ db.select("select count(*) from person") //
187
+ .parameters(1, 2, 3) //
188
+ .getAs(Integer.class) //
189
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
190
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
191
+ .assertValues(3, 3, 3) //
192
+ .assertComplete();
193
+ }
194
+ }
195
+
196
+ @Test
197
+ public void testSelectUsingQuestionMarkFlowableParametersTwoParametersPerQuery() {
198
+ try (Database db = db()) {
199
+ db.select("select score from person where name=? and score = ?") //
200
+ .parameterStream(Flowable.just("FRED", 21, "JOSEPH", 34)) //
201
+ .getAs(Integer.class) //
202
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
203
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
204
+ .assertNoErrors() //
205
+ .assertValues(21, 34) //
206
+ .assertComplete();
207
+ }
208
+ }
209
+
210
+ @Test
211
+ public void testSelectUsingQuestionMarkFlowableParameterListsTwoParametersPerQuery() {
212
+ try (Database db = db()) {
213
+ db.select("select score from person where name=? and score = ?") //
214
+ .parameterListStream(
215
+ Flowable.just(Arrays.asList("FRED", 21), Arrays.asList("JOSEPH", 34))) //
216
+ .getAs(Integer.class) //
217
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
218
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
219
+ .assertNoErrors() //
220
+ .assertValues(21, 34) //
221
+ .assertComplete();
222
+ }
223
+ }
224
+
225
+ @Test
226
+ public void testSelectUsingQuestionMarkWithPublicTestingDatabase() {
227
+ try (Database db = Database.test()) {
228
+ db //
229
+ .select("select score from person where name=?") //
230
+ .parameters("FRED", "JOSEPH") //
231
+ .getAs(Integer.class) //
232
+ .test() //
233
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
234
+ .assertNoErrors() //
235
+ .assertValues(21, 34) //
236
+ .assertComplete();
237
+ }
238
+ }
239
+
240
+ @Test
241
+ public void testSelectWithFetchSize() {
242
+ try (Database db = db()) {
243
+ db.select("select score from person order by name") //
244
+ .fetchSize(2) //
245
+ .getAs(Integer.class) //
246
+ .test() //
247
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
248
+ .assertNoErrors() //
249
+ .assertValues(21, 34, 25) //
250
+ .assertComplete();
251
+ }
252
+ }
253
+
254
+ @Test
255
+ public void testSelectWithFetchSizeZero() {
256
+ try (Database db = db()) {
257
+ db.select("select score from person order by name") //
258
+ .fetchSize(0) //
259
+ .getAs(Integer.class) //
260
+ .test() //
261
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
262
+ .assertNoErrors() //
263
+ .assertValues(21, 34, 25) //
264
+ .assertComplete();
265
+ }
266
+ }
267
+
268
+ @Test(expected = IllegalArgumentException.class)
269
+ public void testSelectWithFetchSizeNegative() {
270
+ try (Database db = db()) {
271
+ db.select("select score from person order by name") //
272
+ .fetchSize(-1);
273
+ }
274
+ }
275
+
276
+ @Test
277
+ public void testSelectUsingNonBlockingBuilder() {
278
+ NonBlockingConnectionPool pool = Pools //
279
+ .nonBlocking() //
280
+ .connectionProvider(DatabaseCreator.connectionProvider()) //
281
+ .maxIdleTime(1, TimeUnit.MINUTES) //
282
+ .idleTimeBeforeHealthCheck(1, TimeUnit.MINUTES) //
283
+ .checkoutRetryInterval(1, TimeUnit.SECONDS) //
284
+ .healthy(c -> c.prepareStatement("select 1").execute()) //
285
+ .returnToPoolDelayAfterHealthCheckFailure(1, TimeUnit.SECONDS) //
286
+ .maxPoolSize(3) //
287
+ .build();
288
+
289
+ try (Database db = Database.from(pool)) {
290
+ db.select("select score from person where name=?") //
291
+ .parameters("FRED", "JOSEPH") //
292
+ .getAs(Integer.class) //
293
+ .test() //
294
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
295
+ .assertNoErrors() //
296
+ .assertValues(21, 34) //
297
+ .assertComplete();
298
+ }
299
+ }
300
+
301
+ @Test(timeout = 40000)
302
+ public void testSelectUsingNonBlockingBuilderConcurrencyTest()
303
+ throws InterruptedException, TimeoutException {
304
+ info();
305
+ try {
306
+ try (Database db = db(3)) {
307
+ Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(50));
308
+ int n = 10000;
309
+ CountDownLatch latch = new CountDownLatch(n);
310
+ AtomicInteger count = new AtomicInteger();
311
+ for (int i = 0; i < n; i++) {
312
+ db.select("select score from person where name=?") //
313
+ .parameters("FRED", "JOSEPH") //
314
+ .getAs(Integer.class) //
315
+ .subscribeOn(scheduler) //
316
+ .toList() //
317
+ .doOnSuccess(x -> {
318
+ if (!x.equals(Lists.newArrayList(21, 34))) {
319
+ throw new RuntimeException("run broken");
320
+ } else {
321
+ // log.debug(iCopy + " succeeded");
322
+ }
323
+ }) //
324
+ .doOnSuccess(x -> {
325
+ count.incrementAndGet();
326
+ latch.countDown();
327
+ }) //
328
+ .doOnError(x -> latch.countDown()) //
329
+ .subscribe();
330
+ }
331
+ if (!latch.await(20, TimeUnit.SECONDS)) {
332
+ throw new TimeoutException("timeout");
333
+ }
334
+ assertEquals(n, count.get());
335
+ }
336
+ } finally {
337
+ debug();
338
+ }
339
+ }
340
+
341
+ @Test(timeout = 5000)
342
+ public void testSelectConcurrencyTest() throws InterruptedException, TimeoutException {
343
+ debug();
344
+ try {
345
+ try (Database db = db(1)) {
346
+ Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(2));
347
+ int n = 2;
348
+ CountDownLatch latch = new CountDownLatch(n);
349
+ AtomicInteger count = new AtomicInteger();
350
+ for (int i = 0; i < n; i++) {
351
+ db.select("select score from person where name=?") //
352
+ .parameters("FRED", "JOSEPH") //
353
+ .getAs(Integer.class) //
354
+ .subscribeOn(scheduler) //
355
+ .toList() //
356
+ .doOnSuccess(x -> {
357
+ if (!x.equals(Lists.newArrayList(21, 34))) {
358
+ throw new RuntimeException("run broken");
359
+ }
360
+ }) //
361
+ .doOnSuccess(x -> {
362
+ count.incrementAndGet();
363
+ latch.countDown();
364
+ }) //
365
+ .doOnError(x -> latch.countDown()) //
366
+ .subscribe();
367
+ log.info("submitted " + i);
368
+ }
369
+ if (!latch.await(5000, TimeUnit.SECONDS)) {
370
+ throw new TimeoutException("timeout");
371
+ }
372
+ assertEquals(n, count.get());
373
+ }
374
+ } finally {
375
+ debug();
376
+ }
377
+ }
378
+
379
+ @Test
380
+ public void testDatabaseClose() {
381
+ try (Database db = db()) {
382
+ db.select("select score from person where name=?") //
383
+ .parameters("FRED", "JOSEPH") //
384
+ .getAs(Integer.class) //
385
+ .test() //
386
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
387
+ .assertNoErrors() //
388
+ .assertValues(21, 34) //
389
+ .assertComplete();
390
+ }
391
+ }
392
+
393
+ @Test
394
+ public void testSelectUsingName() {
395
+ try (Database db = db()) {
396
+ db //
397
+ .select("select score from person where name=:name") //
398
+ .parameter("name", "FRED") //
399
+ .parameter("name", "JOSEPH") //
400
+ .getAs(Integer.class) //
401
+ .test() //
402
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
403
+ .assertValues(21, 34) //
404
+ .assertComplete();
405
+ }
406
+ }
407
+
408
+ @Test
409
+ public void testSelectUsingNameNotGiven() {
410
+ try (Database db = db()) {
411
+ db //
412
+ .select("select score from person where name=:name and name<>:name2") //
413
+ .parameter("name", "FRED") //
414
+ .parameter("name", "JOSEPH") //
415
+ .getAs(Integer.class) //
416
+ .test() //
417
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
418
+ .assertError(NamedParameterMissingException.class) //
419
+ .assertNoValues();
420
+ }
421
+ }
422
+
423
+ @Test
424
+ public void testSelectUsingParameterNameNullNameWhenSqlHasNoNames() {
425
+ db() //
426
+ .select("select score from person where name=?") //
427
+ .parameter(Parameter.create("name", "FRED")) //
428
+ .getAs(Integer.class) //
429
+ .test() //
430
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
431
+ .assertError(NamedParameterFoundButSqlDoesNotHaveNamesException.class) //
432
+ .assertNoValues();
433
+ }
434
+
435
+ @Test
436
+ public void testUpdateWithNull() {
437
+ try (Database db = db()) {
438
+ db //
439
+ .update("update person set date_of_birth = :dob") //
440
+ .parameter(Parameter.create("dob", null)) //
441
+ .counts() //
442
+ .test() //
443
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
444
+ .assertValue(3) //
445
+ .assertComplete();
446
+ }
447
+ }
448
+
449
+ @Test
450
+ public void testUpdateClobWithNull() {
451
+ try (Database db = db()) {
452
+ insertNullClob(db);
453
+ db //
454
+ .update("update person_clob set document = :doc") //
455
+ .parameter("doc", Database.NULL_CLOB) //
456
+ .counts() //
457
+ .test() //
458
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
459
+ .assertValue(1) //
460
+ .assertComplete();
461
+ }
462
+ }
463
+
464
+ @Test
465
+ public void testUpdateClobWithClob() throws SQLException {
466
+ try (Database db = db()) {
467
+ Clob clob = new JDBCClobFile(new File("src/test/resources/big.txt"));
468
+ insertNullClob(db);
469
+ db //
470
+ .update("update person_clob set document = :doc") //
471
+ .parameter("doc", clob) //
472
+ .counts() //
473
+ .test() //
474
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
475
+ .assertValue(1) //
476
+ .assertComplete();
477
+ }
478
+ }
479
+
480
+ @Test
481
+ public void testUpdateClobWithReader() throws FileNotFoundException {
482
+ try (Database db = db()) {
483
+ Reader reader = new FileReader(new File("src/test/resources/big.txt"));
484
+ insertNullClob(db);
485
+ db //
486
+ .update("update person_clob set document = :doc") //
487
+ .parameter("doc", reader) //
488
+ .counts() //
489
+ .test() //
490
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
491
+ .assertValue(1) //
492
+ .assertComplete();
493
+ }
494
+ }
495
+
496
+ @Test
497
+ public void testUpdateBlobWithBlob() throws SQLException {
498
+ try (Database db = db()) {
499
+ Blob blob = new JDBCBlobFile(new File("src/test/resources/big.txt"));
500
+ insertPersonBlob(db);
501
+ db //
502
+ .update("update person_blob set document = :doc") //
503
+ .parameter("doc", blob) //
504
+ .counts() //
505
+ .test() //
506
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
507
+ .assertValue(1) //
508
+ .assertComplete();
509
+ }
510
+ }
511
+
512
+ @Test
513
+ public void testUpdateBlobWithNull() {
514
+ try (Database db = db()) {
515
+ insertPersonBlob(db);
516
+ db //
517
+ .update("update person_blob set document = :doc") //
518
+ .parameter("doc", Database.NULL_BLOB) //
519
+ .counts() //
520
+ .test() //
521
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
522
+ .assertValue(1) //
523
+ .assertComplete();
524
+ }
525
+ }
526
+
527
+ @Test(expected = NullPointerException.class)
528
+ public void testSelectUsingNullNameInParameter() {
529
+ try (Database db = db()) {
530
+ db //
531
+ .select("select score from person where name=:name") //
532
+ .parameter(null, "FRED"); //
533
+ }
534
+ }
535
+
536
+ @Test(expected = IllegalArgumentException.class)
537
+ public void testSelectUsingNameDoesNotExist() {
538
+ try (Database db = db()) {
539
+ db //
540
+ .select("select score from person where name=:name") //
541
+ .parameters("nam", "FRED");
542
+ }
543
+ }
544
+
545
+ @Test(expected = IllegalArgumentException.class)
546
+ public void testSelectUsingNameWithoutSpecifyingNameThrowsImmediately() {
547
+ try (Database db = db()) {
548
+ db //
549
+ .select("select score from person where name=:name") //
550
+ .parameters("FRED", "JOSEPH");
551
+ }
552
+ }
553
+
554
+ @Test
555
+ public void testSelectTransacted() {
556
+ try (Database db = db()) {
557
+ db //
558
+ .select("select score from person where name=?") //
559
+ .parameters("FRED", "JOSEPH") //
560
+ .transacted() //
561
+ .getAs(Integer.class) //
562
+ .doOnNext(tx -> log
563
+ .debug(tx.isComplete() ? "complete" : String.valueOf(tx.value()))) //
564
+ .test() //
565
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
566
+ .assertValueCount(3) //
567
+ .assertComplete();
568
+ }
569
+ }
570
+
571
+ @Test
572
+ public void testSelectAutomappedAnnotatedTransacted() {
573
+ try (Database db = db()) {
574
+ db //
575
+ .select(Person10.class) //
576
+ .transacted() //
577
+ .valuesOnly() //
578
+ .get().test() //
579
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
580
+ .assertValueCount(3) //
581
+ .assertComplete();
582
+ }
583
+ }
584
+
585
+ @Test
586
+ public void testSelectAutomappedTransactedValuesOnly() {
587
+ try (Database db = db()) {
588
+ db //
589
+ .select("select name, score from person") //
590
+ .transacted() //
591
+ .valuesOnly() //
592
+ .autoMap(Person2.class) //
593
+ .test() //
594
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
595
+ .assertValueCount(3) //
596
+ .assertComplete();
597
+ }
598
+ }
599
+
600
+ @Test
601
+ public void testSelectAutomappedTransacted() {
602
+ try (Database db = db()) {
603
+ db //
604
+ .select("select name, score from person") //
605
+ .transacted() //
606
+ .autoMap(Person2.class) //
607
+ .test() //
608
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
609
+ .assertValueCount(4) //
610
+ .assertComplete();
611
+ }
612
+ }
613
+
614
+ @Test
615
+ public void testSelectTransactedTuple2() {
616
+ try (Database db = db()) {
617
+ Tx<Tuple2<String, Integer>> t = db //
618
+ .select("select name, score from person where name=?") //
619
+ .parameters("FRED") //
620
+ .transacted() //
621
+ .getAs(String.class, Integer.class) //
622
+ .test() //
623
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
624
+ .assertValueCount(2) //
625
+ .assertComplete() //
626
+ .values().get(0);
627
+ assertEquals("FRED", t.value()._1());
628
+ assertEquals(21, (int) t.value()._2());
629
+ }
630
+ }
631
+
632
+ @Test
633
+ public void testSelectTransactedTuple3() {
634
+ try (Database db = db()) {
635
+ Tx<Tuple3<String, Integer, String>> t = db //
636
+ .select("select name, score, name from person where name=?") //
637
+ .parameters("FRED") //
638
+ .transacted() //
639
+ .getAs(String.class, Integer.class, String.class) //
640
+ .test() //
641
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
642
+ .assertValueCount(2) //
643
+ .assertComplete() //
644
+ .values().get(0);
645
+ assertEquals("FRED", t.value()._1());
646
+ assertEquals(21, (int) t.value()._2());
647
+ assertEquals("FRED", t.value()._3());
648
+ }
649
+ }
650
+
651
+ @Test
652
+ public void testSelectTransactedTuple4() {
653
+ try (Database db = db()) {
654
+ Tx<Tuple4<String, Integer, String, Integer>> t = db //
655
+ .select("select name, score, name, score from person where name=?") //
656
+ .parameters("FRED") //
657
+ .transacted() //
658
+ .getAs(String.class, Integer.class, String.class, Integer.class) //
659
+ .test() //
660
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
661
+ .assertValueCount(2) //
662
+ .assertComplete() //
663
+ .values().get(0);
664
+ assertEquals("FRED", t.value()._1());
665
+ assertEquals(21, (int) t.value()._2());
666
+ assertEquals("FRED", t.value()._3());
667
+ assertEquals(21, (int) t.value()._4());
668
+ }
669
+ }
670
+
671
+ @Test
672
+ public void testSelectTransactedTuple5() {
673
+ try (Database db = db()) {
674
+ Tx<Tuple5<String, Integer, String, Integer, String>> t = db //
675
+ .select("select name, score, name, score, name from person where name=?") //
676
+ .parameters("FRED") //
677
+ .transacted() //
678
+ .getAs(String.class, Integer.class, String.class, Integer.class, String.class) //
679
+ .test() //
680
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
681
+ .assertValueCount(2) //
682
+ .assertComplete() //
683
+ .values().get(0);
684
+ assertEquals("FRED", t.value()._1());
685
+ assertEquals(21, (int) t.value()._2());
686
+ assertEquals("FRED", t.value()._3());
687
+ assertEquals(21, (int) t.value()._4());
688
+ assertEquals("FRED", t.value()._5());
689
+ }
690
+ }
691
+
692
+ @Test
693
+ public void testSelectTransactedTuple6() {
694
+ try (Database db = db()) {
695
+ Tx<Tuple6<String, Integer, String, Integer, String, Integer>> t = db //
696
+ .select("select name, score, name, score, name, score from person where name=?") //
697
+ .parameters("FRED") //
698
+ .transacted() //
699
+ .getAs(String.class, Integer.class, String.class, Integer.class, String.class,
700
+ Integer.class) //
701
+ .test() //
702
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
703
+ .assertValueCount(2) //
704
+ .assertComplete() //
705
+ .values().get(0);
706
+ assertEquals("FRED", t.value()._1());
707
+ assertEquals(21, (int) t.value()._2());
708
+ assertEquals("FRED", t.value()._3());
709
+ assertEquals(21, (int) t.value()._4());
710
+ assertEquals("FRED", t.value()._5());
711
+ assertEquals(21, (int) t.value()._6());
712
+ }
713
+ }
714
+
715
+ @Test
716
+ public void testSelectTransactedTuple7() {
717
+ try (Database db = db()) {
718
+ Tx<Tuple7<String, Integer, String, Integer, String, Integer, String>> t = db //
719
+ .select("select name, score, name, score, name, score, name from person where name=?") //
720
+ .parameters("FRED") //
721
+ .transacted() //
722
+ .getAs(String.class, Integer.class, String.class, Integer.class, String.class,
723
+ Integer.class, String.class) //
724
+ .test() //
725
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
726
+ .assertValueCount(2) //
727
+ .assertComplete() //
728
+ .values().get(0);
729
+ assertEquals("FRED", t.value()._1());
730
+ assertEquals(21, (int) t.value()._2());
731
+ assertEquals("FRED", t.value()._3());
732
+ assertEquals(21, (int) t.value()._4());
733
+ assertEquals("FRED", t.value()._5());
734
+ assertEquals(21, (int) t.value()._6());
735
+ assertEquals("FRED", t.value()._7());
736
+ }
737
+ }
738
+
739
+ @Test
740
+ public void testSelectTransactedTupleN() {
741
+ List<Tx<TupleN<Object>>> list = db() //
742
+ .select("select name, score from person where name=?") //
743
+ .parameters("FRED") //
744
+ .transacted() //
745
+ .getTupleN() //
746
+ .test() //
747
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
748
+ .assertValueCount(2) //
749
+ .assertComplete() //
750
+ .values();
751
+ assertEquals("FRED", list.get(0).value().values().get(0));
752
+ assertEquals(21, (int) list.get(0).value().values().get(1));
753
+ assertTrue(list.get(1).isComplete());
754
+ assertEquals(2, list.size());
755
+ }
756
+
757
+ @Test
758
+ public void testSelectTransactedCount() {
759
+ db() //
760
+ .select("select name, score, name, score, name, score, name from person where name=?") //
761
+ .parameters("FRED") //
762
+ .transacted() //
763
+ .count() //
764
+ .test() //
765
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
766
+ .assertValueCount(1) //
767
+ .assertComplete();
768
+ }
769
+
770
+ @Test
771
+ public void testSelectTransactedGetAs() {
772
+ db() //
773
+ .select("select name from person") //
774
+ .transacted() //
775
+ .getAs(String.class) //
776
+ .test() //
777
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
778
+ .assertValueCount(4) //
779
+ .assertComplete();
780
+ }
781
+
782
+ @Test
783
+ public void testSelectTransactedGetAsOptional() {
784
+ List<Tx<Optional<String>>> list = db() //
785
+ .select("select name from person where name=?") //
786
+ .parameters("FRED") //
787
+ .transacted() //
788
+ .getAsOptional(String.class) //
789
+ .test() //
790
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
791
+ .assertValueCount(2) //
792
+ .assertComplete() //
793
+ .values();
794
+ assertTrue(list.get(0).isValue());
795
+ assertEquals("FRED", list.get(0).value().get());
796
+ assertTrue(list.get(1).isComplete());
797
+ }
798
+
799
+ @Test
800
+ public void testDatabaseFrom() {
801
+ Database.from(DatabaseCreator.nextUrl(), 3) //
802
+ .select("select name from person") //
803
+ .getAs(String.class) //
804
+ .count() //
805
+ .test() //
806
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
807
+ .assertError(JdbcSQLException.class);
808
+ }
809
+
810
+ @Test
811
+ public void testSelectTransactedChained() throws Exception {
812
+ try (Database db = db()) {
813
+ db //
814
+ .select("select score from person where name=?") //
815
+ .parameters("FRED", "JOSEPH") //
816
+ .transacted() //
817
+ .transactedValuesOnly() //
818
+ .getAs(Integer.class) //
819
+ .doOnNext(tx -> log
820
+ .debug(tx.isComplete() ? "complete" : String.valueOf(tx.value())))//
821
+ .flatMap(tx -> tx //
822
+ .select("select name from person where score = ?") //
823
+ .parameter(tx.value()) //
824
+ .valuesOnly() //
825
+ .getAs(String.class)) //
826
+ .test() //
827
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
828
+ .assertNoErrors() //
829
+ .assertValues("FRED", "JOSEPH") //
830
+ .assertComplete();
831
+ }
832
+ }
833
+
834
+ @Test
835
+ public void databaseIsAutoCloseable() {
836
+ try (Database db = db()) {
837
+ log.debug(db.toString());
838
+ }
839
+ }
840
+
841
+ @Test
842
+ public void testSelectChained() {
843
+ try (Database db = db(1)) {
844
+ // we can do this with 1 connection only!
845
+ db.select("select score from person where name=?") //
846
+ .parameters("FRED", "JOSEPH") //
847
+ .getAs(Integer.class) //
848
+ .doOnNext(System.out::println) //
849
+ .concatMap(score -> {
850
+ log.info("score={}", score);
851
+ return db //
852
+ .select("select name from person where score = ?") //
853
+ .parameter(score) //
854
+ .getAs(String.class) //
855
+ .doOnComplete(
856
+ () -> log.info("completed select where score=" + score));
857
+ }) //
858
+ .test() //
859
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
860
+ .assertNoErrors() //
861
+ .assertValues("FRED", "JOSEPH") //
862
+ .assertComplete(); //
863
+ }
864
+ }
865
+
866
+ @Test
867
+ @SuppressFBWarnings
868
+ public void testReadMeFragment1() {
869
+ try (Database db = db()) {
870
+ db.select("select name from person") //
871
+ .getAs(String.class) //
872
+ .forEach(System.out::println);
873
+ }
874
+ }
875
+
876
+ @Test
877
+ public void testReadMeFragmentColumnDoesNotExistEmitsSqlSyntaxErrorException() {
878
+ try (Database db = Database.test()) {
879
+ db.select("select nam from person") //
880
+ .getAs(String.class) //
881
+ .test() //
882
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
883
+ .assertNoValues() //
884
+ .assertError(SQLSyntaxErrorException.class);
885
+ }
886
+ }
887
+
888
+ @Test
889
+ public void testReadMeFragmentDerbyHealthCheck() {
890
+ try (Database db = Database.test()) {
891
+ db.select("select 'a' from sysibm.sysdummy1") //
892
+ .getAs(String.class) //
893
+ .test() //
894
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
895
+ .assertValue("a") //
896
+ .assertComplete();
897
+ }
898
+ }
899
+
900
+ @Test
901
+ @SuppressFBWarnings
902
+ public void testTupleSupport() {
903
+ try (Database db = db()) {
904
+ db.select("select name, score from person") //
905
+ .getAs(String.class, Integer.class) //
906
+ .forEach(System.out::println);
907
+ }
908
+ }
909
+
910
+ @Test
911
+ public void testDelayedCallsAreNonBlocking() throws InterruptedException {
912
+ List<String> list = new CopyOnWriteArrayList<String>();
913
+ try (Database db = db(1)) { //
914
+ db.select("select score from person where name=?") //
915
+ .parameter("FRED") //
916
+ .getAs(Integer.class) //
917
+ .doOnNext(x -> Thread.sleep(1000)) //
918
+ .subscribeOn(Schedulers.io()) //
919
+ .subscribe();
920
+ Thread.sleep(100);
921
+ CountDownLatch latch = new CountDownLatch(1);
922
+ db.select("select score from person where name=?") //
923
+ .parameter("FRED") //
924
+ .getAs(Integer.class) //
925
+ .doOnNext(x -> list.add("emitted")) //
926
+ .doOnNext(x -> log.debug("emitted on " + Thread.currentThread().getName())) //
927
+ .doOnNext(x -> latch.countDown()) //
928
+ .subscribe();
929
+ list.add("subscribed");
930
+ assertTrue(latch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS));
931
+ assertEquals(Arrays.asList("subscribed", "emitted"), list);
932
+ }
933
+ }
934
+
935
+ @Test
936
+ public void testAutoMapToInterface() {
937
+ try (Database db = db()) {
938
+ db //
939
+ .select("select name from person") //
940
+ .autoMap(Person.class) //
941
+ .map(p -> p.name()) //
942
+ .test() //
943
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
944
+ .assertValueCount(3) //
945
+ .assertComplete();
946
+ }
947
+ }
948
+
949
+ @Test
950
+ public void testAutoMapToInterfaceWithoutAnnotationstsError() {
951
+ try (Database db = db()) {
952
+ db //
953
+ .select("select name from person") //
954
+ .autoMap(PersonNoAnnotation.class) //
955
+ .map(p -> p.name()) //
956
+ .test() //
957
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
958
+ .assertNoValues() //
959
+ .assertError(AnnotationsNotFoundException.class);
960
+ }
961
+ }
962
+
963
+ @Test
964
+ public void testAutoMapToInterfaceWithTwoMethods() {
965
+ try (Database db = db()) {
966
+ db //
967
+ .select("select name, score from person order by name") //
968
+ .autoMap(Person2.class) //
969
+ .firstOrError() //
970
+ .map(Person2::score) //
971
+ .test() //
972
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
973
+ .assertValue(21) //
974
+ .assertComplete();
975
+ }
976
+ }
977
+
978
+ @Test
979
+ public void testAutoMapToInterfaceWithExplicitColumnName() {
980
+ try (Database db = db()) {
981
+ db //
982
+ .select("select name, score from person order by name") //
983
+ .autoMap(Person3.class) //
984
+ .firstOrError() //
985
+ .map(Person3::examScore) //
986
+ .test() //
987
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
988
+ .assertValue(21) //
989
+ .assertComplete();
990
+ }
991
+ }
992
+
993
+ @Test
994
+ public void testAutoMapToInterfaceWithExplicitColumnNameThatDoesNotExist() {
995
+ try (Database db = db()) {
996
+ db //
997
+ .select("select name, score from person order by name") //
998
+ .autoMap(Person4.class) //
999
+ .firstOrError() //
1000
+ .map(Person4::examScore) //
1001
+ .test() //
1002
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1003
+ .assertNoValues() //
1004
+ .assertError(ColumnNotFoundException.class);
1005
+ }
1006
+ }
1007
+
1008
+ @Test
1009
+ public void testAutoMapToInterfaceWithIndex() {
1010
+ try (Database db = db()) {
1011
+ db //
1012
+ .select("select name, score from person order by name") //
1013
+ .autoMap(Person5.class) //
1014
+ .firstOrError() //
1015
+ .map(Person5::examScore) //
1016
+ .test() //
1017
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1018
+ .assertValue(21) //
1019
+ .assertComplete();
1020
+ }
1021
+ }
1022
+
1023
+ @Test
1024
+ public void testAutoMapToInterfaceWithIndexTooLarge() {
1025
+ try (Database db = db()) {
1026
+ db //
1027
+ .select("select name, score from person order by name") //
1028
+ .autoMap(Person6.class) //
1029
+ .firstOrError() //
1030
+ .map(Person6::examScore) //
1031
+ .test() //
1032
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1033
+ .assertNoValues() //
1034
+ .assertError(ColumnIndexOutOfRangeException.class);
1035
+ }
1036
+ }
1037
+
1038
+ @Test
1039
+ public void testAutoMapToInterfaceWithIndexTooSmall() {
1040
+ try (Database db = db()) {
1041
+ db //
1042
+ .select("select name, score from person order by name") //
1043
+ .autoMap(Person7.class) //
1044
+ .firstOrError() //
1045
+ .map(Person7::examScore) //
1046
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1047
+ .assertNoValues() //
1048
+ .assertError(ColumnIndexOutOfRangeException.class);
1049
+ }
1050
+ }
1051
+
1052
+ @Test
1053
+ public void testAutoMapWithUnmappableColumnType() {
1054
+ try (Database db = db()) {
1055
+ db //
1056
+ .select("select name from person order by name") //
1057
+ .autoMap(Person8.class) //
1058
+ .map(p -> p.name()) //
1059
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1060
+ .assertNoValues() //
1061
+ .assertError(ClassCastException.class);
1062
+ }
1063
+ }
1064
+
1065
+ @Test
1066
+ public void testAutoMapWithMixIndexAndName() {
1067
+ try (Database db = db()) {
1068
+ db //
1069
+ .select("select name, score from person order by name") //
1070
+ .autoMap(Person9.class) //
1071
+ .firstOrError() //
1072
+ .map(Person9::score) //
1073
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1074
+ .assertValue(21) //
1075
+ .assertComplete();
1076
+ }
1077
+ }
1078
+
1079
+ @Test
1080
+ public void testAutoMapWithQueryInAnnotation() {
1081
+ try (Database db = db()) {
1082
+ db.select(Person10.class) //
1083
+ .get() //
1084
+ .firstOrError() //
1085
+ .map(Person10::score) //
1086
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1087
+ .assertValue(21) //
1088
+ .assertComplete();
1089
+ }
1090
+ }
1091
+
1092
+ @Test
1093
+ @Ignore
1094
+ public void testAutoMapForReadMe() {
1095
+ Database //
1096
+ .test() //
1097
+ .select(Person10.class) //
1098
+ .get(Person10::name) //
1099
+ .blockingForEach(System.out::println);
1100
+ }
1101
+
1102
+ @Test(expected = QueryAnnotationMissingException.class)
1103
+ public void testAutoMapWithoutQueryInAnnotation() {
1104
+ try (Database db = db()) {
1105
+ db.select(Person.class);
1106
+ }
1107
+ }
1108
+
1109
+ @Test
1110
+ public void testSelectWithoutWhereClause() {
1111
+ try (Database db = db()) {
1112
+ Assert.assertEquals(3, (long) db.select("select name from person") //
1113
+ .count() //
1114
+ .blockingGet());
1115
+ }
1116
+ }
1117
+
1118
+ @Test
1119
+ public void testTuple3() {
1120
+ try (Database db = db()) {
1121
+ db //
1122
+ .select("select name, score, name from person order by name") //
1123
+ .getAs(String.class, Integer.class, String.class) //
1124
+ .firstOrError() //
1125
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1126
+ .assertComplete() //
1127
+ .assertValue(Tuple3.create("FRED", 21, "FRED")); //
1128
+ }
1129
+ }
1130
+
1131
+ @Test
1132
+ public void testTuple4() {
1133
+ try (Database db = db()) {
1134
+ db //
1135
+ .select("select name, score, name, score from person order by name") //
1136
+ .getAs(String.class, Integer.class, String.class, Integer.class) //
1137
+ .firstOrError() //
1138
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1139
+ .assertComplete() //
1140
+ .assertValue(Tuple4.create("FRED", 21, "FRED", 21)); //
1141
+ }
1142
+ }
1143
+
1144
+ @Test
1145
+ public void testTuple5() {
1146
+ try (Database db = db()) {
1147
+ db //
1148
+ .select("select name, score, name, score, name from person order by name") //
1149
+ .getAs(String.class, Integer.class, String.class, Integer.class, String.class) //
1150
+ .firstOrError() //
1151
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1152
+ .assertComplete().assertValue(Tuple5.create("FRED", 21, "FRED", 21, "FRED")); //
1153
+ }
1154
+ }
1155
+
1156
+ @Test
1157
+ public void testTuple6() {
1158
+ try (Database db = db()) {
1159
+ db //
1160
+ .select("select name, score, name, score, name, score from person order by name") //
1161
+ .getAs(String.class, Integer.class, String.class, Integer.class, String.class,
1162
+ Integer.class) //
1163
+ .firstOrError() //
1164
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1165
+ .assertComplete()
1166
+ .assertValue(Tuple6.create("FRED", 21, "FRED", 21, "FRED", 21)); //
1167
+ }
1168
+ }
1169
+
1170
+ @Test
1171
+ public void testTuple7() {
1172
+ try (Database db = db()) {
1173
+ db //
1174
+ .select("select name, score, name, score, name, score, name from person order by name") //
1175
+ .getAs(String.class, Integer.class, String.class, Integer.class, String.class,
1176
+ Integer.class, String.class) //
1177
+ .firstOrError() //
1178
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1179
+ .assertComplete()
1180
+ .assertValue(Tuple7.create("FRED", 21, "FRED", 21, "FRED", 21, "FRED")); //
1181
+ }
1182
+ }
1183
+
1184
+ @Test
1185
+ public void testTupleN() {
1186
+ try (Database db = db()) {
1187
+ db //
1188
+ .select("select name, score, name from person order by name") //
1189
+ .getTupleN() //
1190
+ .firstOrError().test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1191
+ .assertComplete() //
1192
+ .assertValue(TupleN.create("FRED", 21, "FRED")); //
1193
+ }
1194
+ }
1195
+
1196
+ @Test
1197
+ public void testHealthCheck() throws InterruptedException {
1198
+ AtomicBoolean once = new AtomicBoolean(true);
1199
+ testHealthCheck(c -> {
1200
+ log.debug("doing health check");
1201
+ return !once.compareAndSet(true, false);
1202
+ });
1203
+ }
1204
+
1205
+ @Test
1206
+ public void testHealthCheckThatThrows() throws InterruptedException {
1207
+ AtomicBoolean once = new AtomicBoolean(true);
1208
+ testHealthCheck(c -> {
1209
+ log.debug("doing health check");
1210
+ if (!once.compareAndSet(true, false))
1211
+ return true;
1212
+ else
1213
+ throw new RuntimeException("health check failed");
1214
+ });
1215
+ }
1216
+
1217
+ @Test
1218
+ public void testUpdateOneRow() {
1219
+ try (Database db = db()) {
1220
+ db.update("update person set score=20 where name='FRED'") //
1221
+ .counts() //
1222
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1223
+ .assertValue(1) //
1224
+ .assertComplete();
1225
+ }
1226
+ }
1227
+
1228
+ @Test
1229
+ public void testUpdateThreeRows() {
1230
+ try (Database db = db()) {
1231
+ db.update("update person set score=20") //
1232
+ .counts() //
1233
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1234
+ .assertValue(3) //
1235
+ .assertComplete();
1236
+ }
1237
+ }
1238
+
1239
+ @Test
1240
+ public void testUpdateWithParameter() {
1241
+ try (Database db = db()) {
1242
+ db.update("update person set score=20 where name=?") //
1243
+ .parameter("FRED").counts() //
1244
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1245
+ .assertValue(1) //
1246
+ .assertComplete();
1247
+ }
1248
+ }
1249
+
1250
+ @Test
1251
+ public void testUpdateWithParameterTwoRuns() {
1252
+ try (Database db = db()) {
1253
+ db.update("update person set score=20 where name=?") //
1254
+ .parameters("FRED", "JOSEPH").counts() //
1255
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1256
+ .assertValues(1, 1) //
1257
+ .assertComplete();
1258
+ }
1259
+ }
1260
+
1261
+ @Test
1262
+ public void testUpdateAllWithParameterFourRuns() {
1263
+ try (Database db = db()) {
1264
+ db.update("update person set score=?") //
1265
+ .parameters(1, 2, 3, 4) //
1266
+ .counts() //
1267
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1268
+ .assertValues(3, 3, 3, 3) //
1269
+ .assertComplete();
1270
+ }
1271
+ }
1272
+
1273
+ @Test
1274
+ public void testUpdateWithBatchSize2() {
1275
+ try (Database db = db()) {
1276
+ db.update("update person set score=?") //
1277
+ .batchSize(2) //
1278
+ .parameters(1, 2, 3, 4) //
1279
+ .counts() //
1280
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1281
+ .assertValues(3, 3, 3, 3) //
1282
+ .assertComplete();
1283
+ }
1284
+ }
1285
+
1286
+ @Test
1287
+ public void testUpdateWithBatchSize3GreaterThanNumRecords() {
1288
+ try (Database db = db()) {
1289
+ db.update("update person set score=?") //
1290
+ .batchSize(3) //
1291
+ .parameters(1, 2, 3, 4) //
1292
+ .counts() //
1293
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1294
+ .assertValues(3, 3, 3, 3) //
1295
+ .assertComplete();
1296
+ }
1297
+ }
1298
+
1299
+ @Test
1300
+ public void testInsert() {
1301
+ try (Database db = db()) {
1302
+ db.update("insert into person(name, score) values(?,?)") //
1303
+ .parameters("DAVE", 12, "ANNE", 18) //
1304
+ .counts() //
1305
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1306
+ .assertValues(1, 1) //
1307
+ .assertComplete();
1308
+ List<Tuple2<String, Integer>> list = db.select("select name, score from person") //
1309
+ .getAs(String.class, Integer.class) //
1310
+ .toList() //
1311
+ .timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1312
+ .blockingGet();
1313
+ assertTrue(list.contains(Tuple2.create("DAVE", 12)));
1314
+ assertTrue(list.contains(Tuple2.create("ANNE", 18)));
1315
+ }
1316
+ }
1317
+
1318
+ @Test
1319
+ public void testReturnGeneratedKeys() {
1320
+ try (Database db = db()) {
1321
+ // note is a table with auto increment
1322
+ db.update("insert into note(text) values(?)") //
1323
+ .parameters("HI", "THERE") //
1324
+ .returnGeneratedKeys() //
1325
+ .getAs(Integer.class)//
1326
+ .test() //
1327
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1328
+ .assertValues(1, 2) //
1329
+ .assertComplete();
1330
+
1331
+ db.update("insert into note(text) values(?)") //
1332
+ .parameters("ME", "TOO") //
1333
+ .returnGeneratedKeys() //
1334
+ .getAs(Integer.class)//
1335
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1336
+ .assertValues(3, 4) //
1337
+ .assertComplete();
1338
+ }
1339
+ }
1340
+
1341
+ @Test
1342
+ public void testReturnGeneratedKeysDerby() {
1343
+ Database db = DatabaseCreator.createDerby(1);
1344
+
1345
+ // note is a table with auto increment
1346
+ db.update("insert into note2(text) values(?)") //
1347
+ .parameters("HI", "THERE") //
1348
+ .returnGeneratedKeys() //
1349
+ .getAs(Integer.class)//
1350
+ .test() //
1351
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1352
+ .assertNoErrors().assertValues(1, 3) //
1353
+ .assertComplete();
1354
+
1355
+ db.update("insert into note2(text) values(?)") //
1356
+ .parameters("ME", "TOO") //
1357
+ .returnGeneratedKeys() //
1358
+ .getAs(Integer.class)//
1359
+ .test() //
1360
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1361
+ .assertValues(5, 7) //
1362
+ .assertComplete();
1363
+ }
1364
+
1365
+ @Test(expected = IllegalArgumentException.class)
1366
+ public void testReturnGeneratedKeysWithBatchSizeShouldThrow() {
1367
+ try (Database db = db()) {
1368
+ // note is a table with auto increment
1369
+ db.update("insert into note(text) values(?)") //
1370
+ .parameters("HI", "THERE") //
1371
+ .batchSize(2) //
1372
+ .returnGeneratedKeys();
1373
+ }
1374
+ }
1375
+
1376
+ @Test
1377
+ public void testTransactedReturnGeneratedKeys() {
1378
+ try (Database db = db()) {
1379
+ // note is a table with auto increment
1380
+ db.update("insert into note(text) values(?)") //
1381
+ .parameters("HI", "THERE") //
1382
+ .transacted() //
1383
+ .returnGeneratedKeys() //
1384
+ .valuesOnly() //
1385
+ .getAs(Integer.class)//
1386
+ .test() //
1387
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1388
+ .assertValues(1, 2) //
1389
+ .assertComplete();
1390
+
1391
+ db.update("insert into note(text) values(?)") //
1392
+ .parameters("ME", "TOO") //
1393
+ .transacted() //
1394
+ .returnGeneratedKeys() //
1395
+ .valuesOnly() //
1396
+ .getAs(Integer.class)//
1397
+ .test() //
1398
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1399
+ .assertValues(3, 4) //
1400
+ .assertComplete();
1401
+ }
1402
+ }
1403
+
1404
+ @Test
1405
+ public void testTransactedReturnGeneratedKeys2() {
1406
+ try (Database db = db()) {
1407
+ // note is a table with auto increment
1408
+ Flowable<Integer> a = db.update("insert into note(text) values(?)") //
1409
+ .parameters("HI", "THERE") //
1410
+ .transacted() //
1411
+ .returnGeneratedKeys() //
1412
+ .valuesOnly() //
1413
+ .getAs(Integer.class);
1414
+
1415
+ db.update("insert into note(text) values(?)") //
1416
+ .parameters("ME", "TOO") //
1417
+ .transacted() //
1418
+ .returnGeneratedKeys() //
1419
+ .valuesOnly() //
1420
+ .getAs(Integer.class)//
1421
+ .startWith(a) //
1422
+ .test() //
1423
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1424
+ .assertValues(1, 2, 3, 4) //
1425
+ .assertComplete();
1426
+ }
1427
+ }
1428
+
1429
+ @Test
1430
+ public void testUpdateWithinTransaction() {
1431
+ try (Database db = db()) {
1432
+ db //
1433
+ .select("select name from person") //
1434
+ .transactedValuesOnly() //
1435
+ .getAs(String.class) //
1436
+ .doOnNext(System.out::println) //
1437
+ .flatMap(tx -> tx//
1438
+ .update("update person set score=-1 where name=:name") //
1439
+ .batchSize(1) //
1440
+ .parameter("name", tx.value()) //
1441
+ .valuesOnly() //
1442
+ .counts()) //
1443
+ .test() //
1444
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1445
+ .assertValues(1, 1, 1) //
1446
+ .assertComplete();
1447
+ }
1448
+ }
1449
+
1450
+ @Test
1451
+ public void testSelectDependsOnFlowable() {
1452
+ try (Database db = db()) {
1453
+ Flowable<Integer> a = db.update("update person set score=100 where name=?") //
1454
+ .parameter("FRED") //
1455
+ .counts();
1456
+ db.select("select score from person where name=?") //
1457
+ .parameter("FRED") //
1458
+ .dependsOn(a) //
1459
+ .getAs(Integer.class)//
1460
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1461
+ .assertValues(100) //
1462
+ .assertComplete();
1463
+ }
1464
+ }
1465
+
1466
+ @Test
1467
+ public void testSelectDependsOnObservable() {
1468
+ try (Database db = db()) {
1469
+ Observable<Integer> a = db.update("update person set score=100 where name=?") //
1470
+ .parameter("FRED") //
1471
+ .counts().toObservable();
1472
+ db.select("select score from person where name=?") //
1473
+ .parameter("FRED") //
1474
+ .dependsOn(a) //
1475
+ .getAs(Integer.class)//
1476
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1477
+ .assertValues(100) //
1478
+ .assertComplete();
1479
+ }
1480
+ }
1481
+
1482
+ @Test
1483
+ public void testSelectDependsOnOnSingle() {
1484
+ try (Database db = db()) {
1485
+ Single<Long> a = db.update("update person set score=100 where name=?") //
1486
+ .parameter("FRED") //
1487
+ .counts().count();
1488
+ db.select("select score from person where name=?") //
1489
+ .parameter("FRED") //
1490
+ .dependsOn(a) //
1491
+ .getAs(Integer.class)//
1492
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1493
+ .assertValues(100) //
1494
+ .assertComplete();
1495
+ }
1496
+ }
1497
+
1498
+ @Test
1499
+ public void testSelectDependsOnCompletable() {
1500
+ try (Database db = db()) {
1501
+ Completable a = db.update("update person set score=100 where name=?") //
1502
+ .parameter("FRED") //
1503
+ .counts().ignoreElements();
1504
+ db.select("select score from person where name=?") //
1505
+ .parameter("FRED") //
1506
+ .dependsOn(a) //
1507
+ .getAs(Integer.class)//
1508
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1509
+ .assertValues(100) //
1510
+ .assertComplete();
1511
+ }
1512
+ }
1513
+
1514
+ @Test
1515
+ public void testUpdateWithinTransactionBatchSize0() {
1516
+ try (Database db = db()) {
1517
+ db //
1518
+ .select("select name from person") //
1519
+ .transactedValuesOnly() //
1520
+ .getAs(String.class) //
1521
+ .doOnNext(System.out::println) //
1522
+ .flatMap(tx -> tx//
1523
+ .update("update person set score=-1 where name=:name") //
1524
+ .batchSize(0) //
1525
+ .parameter("name", tx.value()) //
1526
+ .valuesOnly() //
1527
+ .counts()) //
1528
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1529
+ .assertValues(1, 1, 1) //
1530
+ .assertComplete();
1531
+ }
1532
+ }
1533
+
1534
+ private static void info() {
1535
+ LogManager.getRootLogger().setLevel(Level.INFO);
1536
+ }
1537
+
1538
+ private static void debug() {
1539
+ LogManager.getRootLogger().setLevel(Level.INFO);
1540
+ }
1541
+
1542
+ @Test
1543
+ public void testCreateBig() {
1544
+ info();
1545
+ big(5).select("select count(*) from person") //
1546
+ .getAs(Integer.class) //
1547
+ .test().awaitDone(20, TimeUnit.SECONDS) //
1548
+ .assertValue(5163) //
1549
+ .assertComplete();
1550
+ debug();
1551
+ }
1552
+
1553
+ @Test
1554
+ public void testTxWithBig() {
1555
+ info();
1556
+ big(1) //
1557
+ .select("select name from person") //
1558
+ .transactedValuesOnly() //
1559
+ .getAs(String.class) //
1560
+ .flatMap(tx -> tx//
1561
+ .update("update person set score=-1 where name=:name") //
1562
+ .batchSize(1) //
1563
+ .parameter("name", tx.value()) //
1564
+ .valuesOnly() //
1565
+ .counts()) //
1566
+ .count() //
1567
+ .test().awaitDone(20, TimeUnit.SECONDS) //
1568
+ .assertValue((long) NAMES_COUNT_BIG) //
1569
+ .assertComplete();
1570
+ debug();
1571
+ }
1572
+
1573
+ @Test
1574
+ public void testTxWithBigInputBatchSize2000() {
1575
+ info();
1576
+ big(1) //
1577
+ .select("select name from person") //
1578
+ .transactedValuesOnly() //
1579
+ .getAs(String.class) //
1580
+ .flatMap(tx -> tx//
1581
+ .update("update person set score=-1 where name=:name") //
1582
+ .batchSize(2000) //
1583
+ .parameter("name", tx.value()) //
1584
+ .valuesOnly() //
1585
+ .counts()) //
1586
+ .count() //
1587
+ .test().awaitDone(20, TimeUnit.SECONDS) //
1588
+ .assertValue((long) NAMES_COUNT_BIG) //
1589
+ .assertComplete();
1590
+ debug();
1591
+ }
1592
+
1593
+ @Test
1594
+ public void testInsertNullClobAndReadClobAsString() {
1595
+ try (Database db = db()) {
1596
+ insertNullClob(db);
1597
+ db.select("select document from person_clob where name='FRED'") //
1598
+ .getAsOptional(String.class) //
1599
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1600
+ .assertValue(Optional.<String>empty()) //
1601
+ .assertComplete();
1602
+ }
1603
+ }
1604
+
1605
+ private static void insertNullClob(Database db) {
1606
+ db.update("insert into person_clob(name,document) values(?,?)") //
1607
+ .parameters("FRED", Database.NULL_CLOB) //
1608
+ .counts() //
1609
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1610
+ .assertValue(1) //
1611
+ .assertComplete();
1612
+ }
1613
+
1614
+ @Test
1615
+ public void testClobMethod() {
1616
+ assertEquals(Database.NULL_CLOB, Database.clob(null));
1617
+ }
1618
+
1619
+ @Test
1620
+ public void testBlobMethod() {
1621
+ assertEquals(Database.NULL_BLOB, Database.blob(null));
1622
+ }
1623
+
1624
+ @Test
1625
+ public void testClobMethodPresent() {
1626
+ assertEquals("a", Database.clob("a"));
1627
+ }
1628
+
1629
+ @Test
1630
+ public void testBlobMethodPresent() {
1631
+ byte[] b = new byte[1];
1632
+ assertEquals(b, Database.blob(b));
1633
+ }
1634
+
1635
+ @Test
1636
+ public void testDateOfBirthNullableForReadMe() {
1637
+ Database.test() //
1638
+ .select("select date_of_birth from person where name='FRED'") //
1639
+ .getAsOptional(Instant.class) //
1640
+ .blockingForEach(System.out::println);
1641
+ }
1642
+
1643
+ @Test
1644
+ public void testInsertNullClobAndReadClobAsTuple2() {
1645
+ try (Database db = db()) {
1646
+ insertNullClob(db);
1647
+ db.select("select document, document from person_clob where name='FRED'") //
1648
+ .getAs(String.class, String.class) //
1649
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1650
+ .assertValue(Tuple2.create(null, null)) //
1651
+ .assertComplete();
1652
+ }
1653
+ }
1654
+
1655
+ @Test
1656
+ public void testInsertClobAndReadClobAsString() {
1657
+ try (Database db = db()) {
1658
+ db.update("insert into person_clob(name,document) values(?,?)") //
1659
+ .parameters("FRED", "some text here") //
1660
+ .counts() //
1661
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1662
+ .assertValue(1) //
1663
+ .assertComplete();
1664
+ db.select("select document from person_clob where name='FRED'") //
1665
+ .getAs(String.class) //
1666
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) // .assertValue("some
1667
+ // text
1668
+ // here")
1669
+ // //
1670
+ .assertComplete();
1671
+ }
1672
+ }
1673
+
1674
+ @Test
1675
+ public void testInsertClobAndReadClobUsingReader() {
1676
+ try (Database db = db()) {
1677
+ db.update("insert into person_clob(name,document) values(?,?)") //
1678
+ .parameters("FRED", "some text here") //
1679
+ .counts() //
1680
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1681
+ .assertValue(1) //
1682
+ .assertComplete();
1683
+ db.select("select document from person_clob where name='FRED'") //
1684
+ .getAs(Reader.class) //
1685
+ .map(r -> read(r)).test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1686
+ .assertValue("some text here") //
1687
+ .assertComplete();
1688
+ }
1689
+ }
1690
+
1691
+ @Test
1692
+ public void testInsertBlobAndReadBlobAsByteArray() {
1693
+ try (Database db = db()) {
1694
+ insertPersonBlob(db);
1695
+ db.select("select document from person_blob where name='FRED'") //
1696
+ .getAs(byte[].class) //
1697
+ .map(b -> new String(b)) //
1698
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1699
+ .assertValue("some text here") //
1700
+ .assertComplete();
1701
+ }
1702
+ }
1703
+
1704
+ private static void insertPersonBlob(Database db) {
1705
+ byte[] bytes = "some text here".getBytes();
1706
+ db.update("insert into person_blob(name,document) values(?,?)") //
1707
+ .parameters("FRED", bytes) //
1708
+ .counts() //
1709
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1710
+ .assertValue(1) //
1711
+ .assertComplete();
1712
+ }
1713
+
1714
+ @Test
1715
+ public void testInsertBlobAndReadBlobAsInputStream() {
1716
+ try (Database db = db()) {
1717
+ byte[] bytes = "some text here".getBytes();
1718
+ db.update("insert into person_blob(name,document) values(?,?)") //
1719
+ .parameters("FRED", new ByteArrayInputStream(bytes)) //
1720
+ .counts() //
1721
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1722
+ .assertValue(1) //
1723
+ .assertComplete();
1724
+ db.select("select document from person_blob where name='FRED'") //
1725
+ .getAs(InputStream.class) //
1726
+ .map(is -> read(is)) //
1727
+ .map(b -> new String(b)) //
1728
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1729
+ .assertValue("some text here") //
1730
+ .assertComplete();
1731
+ }
1732
+ }
1733
+
1734
+ private static String read(Reader reader) throws IOException {
1735
+ StringBuffer s = new StringBuffer();
1736
+ char[] ch = new char[128];
1737
+ int n = 0;
1738
+ while ((n = reader.read(ch)) != -1) {
1739
+ s.append(ch, 0, n);
1740
+ }
1741
+ reader.close();
1742
+ return s.toString();
1743
+ }
1744
+
1745
+ private static byte[] read(InputStream is) throws IOException {
1746
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
1747
+ byte[] b = new byte[128];
1748
+ int n = 0;
1749
+ while ((n = is.read(b)) != -1) {
1750
+ bytes.write(b, 0, n);
1751
+ }
1752
+ is.close();
1753
+ return bytes.toByteArray();
1754
+ }
1755
+
1756
+ private void testHealthCheck(Predicate<Connection> healthy) throws InterruptedException {
1757
+ TestScheduler scheduler = new TestScheduler();
1758
+
1759
+ NonBlockingConnectionPool pool = Pools //
1760
+ .nonBlocking() //
1761
+ .connectionProvider(DatabaseCreator.connectionProvider()) //
1762
+ .maxIdleTime(10, TimeUnit.MINUTES) //
1763
+ .idleTimeBeforeHealthCheck(0, TimeUnit.MINUTES) //
1764
+ .healthy(healthy) //
1765
+ .returnToPoolDelayAfterHealthCheckFailure(1, TimeUnit.MINUTES) //
1766
+ .scheduler(scheduler) //
1767
+ .maxPoolSize(1) //
1768
+ .build();
1769
+
1770
+ try (Database db = Database.from(pool)) {
1771
+ TestSubscriber<Integer> ts0 = db.select( //
1772
+ "select score from person where name=?") //
1773
+ .parameter("FRED") //
1774
+ .getAs(Integer.class) //
1775
+ .test();
1776
+ ts0.assertValueCount(0) //
1777
+ .assertNotComplete();
1778
+ scheduler.advanceTimeBy(1, TimeUnit.MINUTES);
1779
+ ts0.assertValueCount(1) //
1780
+ .assertComplete();
1781
+ TestSubscriber<Integer> ts = db.select( //
1782
+ "select score from person where name=?") //
1783
+ .parameter("FRED") //
1784
+ .getAs(Integer.class) //
1785
+ .test() //
1786
+ .assertValueCount(0);
1787
+ log.debug("done2");
1788
+ scheduler.advanceTimeBy(1, TimeUnit.MINUTES);
1789
+ Thread.sleep(200);
1790
+ ts.assertValueCount(1);
1791
+ Thread.sleep(200);
1792
+ ts.assertValue(21) //
1793
+ .assertComplete();
1794
+ }
1795
+ }
1796
+
1797
+ @Test
1798
+ public void testShutdownBeforeUse() {
1799
+ NonBlockingConnectionPool pool = Pools //
1800
+ .nonBlocking() //
1801
+ .connectionProvider(DatabaseCreator.connectionProvider()) //
1802
+ .scheduler(Schedulers.io()) //
1803
+ .maxPoolSize(1) //
1804
+ .build();
1805
+ pool.close();
1806
+ Database.from(pool) //
1807
+ .select("select score from person where name=?") //
1808
+ .parameter("FRED") //
1809
+ .getAs(Integer.class) //
1810
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1811
+ .assertNoValues() //
1812
+ .assertError(PoolClosedException.class);
1813
+ }
1814
+
1815
+ @Test
1816
+ public void testFewerColumnsMappedThanAvailable() {
1817
+ db().select("select name, score from person where name='FRED'") //
1818
+ .getAs(String.class) //
1819
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1820
+ .assertValues("FRED") //
1821
+ .assertComplete();
1822
+ }
1823
+
1824
+ @Test
1825
+ public void testMoreColumnsMappedThanAvailable() {
1826
+ db() //
1827
+ .select("select name, score from person where name='FRED'") //
1828
+ .getAs(String.class, Integer.class, String.class) //
1829
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1830
+ .assertNoValues() //
1831
+ .assertError(MoreColumnsRequestedThanExistException.class);
1832
+ }
1833
+
1834
+ @Test
1835
+ public void testSelectTimestamp() {
1836
+ db() //
1837
+ .select("select registered from person where name='FRED'") //
1838
+ .getAs(Long.class) //
1839
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1840
+ .assertValue(FRED_REGISTERED_TIME) //
1841
+ .assertComplete();
1842
+ }
1843
+
1844
+ @Test
1845
+ public void testSelectTimestampAsDate() {
1846
+ db() //
1847
+ .select("select registered from person where name='FRED'") //
1848
+ .getAs(Date.class) //
1849
+ .map(d -> d.getTime()) //
1850
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1851
+ .assertValue(FRED_REGISTERED_TIME) //
1852
+ .assertComplete();
1853
+ }
1854
+
1855
+ @Test
1856
+ public void testSelectTimestampAsInstant() {
1857
+ db() //
1858
+ .select("select registered from person where name='FRED'") //
1859
+ .getAs(Instant.class) //
1860
+ .map(d -> d.toEpochMilli()) //
1861
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1862
+ .assertValue(FRED_REGISTERED_TIME) //
1863
+ .assertComplete();
1864
+ }
1865
+
1866
+ @Test
1867
+ public void testUpdateCalendarParameter() {
1868
+ Calendar c = GregorianCalendar.from(ZonedDateTime.parse("2017-03-25T15:37Z"));
1869
+ try (Database db = db()) {
1870
+ db.update("update person set registered=?") //
1871
+ .parameter(c) //
1872
+ .counts() //
1873
+ .test() //
1874
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1875
+ .assertValue(3) //
1876
+ .assertComplete();
1877
+ db.select("select registered from person") //
1878
+ .getAs(Long.class) //
1879
+ .firstOrError() //
1880
+ .test() //
1881
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1882
+ .assertValue(c.getTimeInMillis()) //
1883
+ .assertComplete();
1884
+ }
1885
+ }
1886
+
1887
+ @Test
1888
+ public void testUpdateTimeParameter() {
1889
+ try (Database db = db()) {
1890
+ Time t = new Time(1234);
1891
+ db.update("update person set registered=?") //
1892
+ .parameter(t) //
1893
+ .counts() //
1894
+ .test() //
1895
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1896
+ .assertValue(3) //
1897
+ .assertComplete();
1898
+ db.select("select registered from person") //
1899
+ .getAs(Long.class) //
1900
+ .firstOrError() //
1901
+ .test() //
1902
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1903
+ .assertValue(1234L) //
1904
+ .assertComplete();
1905
+ }
1906
+ }
1907
+
1908
+ @Test
1909
+ public void testUpdateTimestampParameter() {
1910
+ try (Database db = db()) {
1911
+ Timestamp t = new Timestamp(1234);
1912
+ db.update("update person set registered=?") //
1913
+ .parameter(t) //
1914
+ .counts() //
1915
+ .test() //
1916
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1917
+ .assertValue(3) //
1918
+ .assertComplete();
1919
+ db.select("select registered from person") //
1920
+ .getAs(Long.class) //
1921
+ .firstOrError() //
1922
+ .test() //
1923
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1924
+ .assertValue(1234L) //
1925
+ .assertComplete();
1926
+ }
1927
+ }
1928
+
1929
+ @Test
1930
+ public void testUpdateSqlDateParameter() {
1931
+ try (Database db = db()) {
1932
+ java.sql.Date t = new java.sql.Date(1234);
1933
+
1934
+ db.update("update person set registered=?") //
1935
+ .parameter(t) //
1936
+ .counts() //
1937
+ .test() //
1938
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1939
+ .assertValue(3) //
1940
+ .assertComplete();
1941
+ db.select("select registered from person") //
1942
+ .getAs(Long.class) //
1943
+ .firstOrError() //
1944
+ .test() //
1945
+ .awaitDone(TIMEOUT_SECONDS * 10000, TimeUnit.SECONDS) //
1946
+ // TODO make a more accurate comparison using the current TZ
1947
+ .assertValue(x -> Math.abs(x - 1234) <= TimeUnit.HOURS.toMillis(24)) //
1948
+ .assertComplete();
1949
+ }
1950
+ }
1951
+
1952
+ @Test
1953
+ public void testUpdateUtilDateParameter() {
1954
+ try (Database db = db()) {
1955
+ Date d = new Date(1234);
1956
+ db.update("update person set registered=?") //
1957
+ .parameter(d) //
1958
+ .counts() //
1959
+ .test() //
1960
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1961
+ .assertValue(3) //
1962
+ .assertComplete();
1963
+ db.select("select registered from person") //
1964
+ .getAs(Long.class) //
1965
+ .firstOrError() //
1966
+ .test() //
1967
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1968
+ .assertValue(1234L) //
1969
+ .assertComplete();
1970
+ }
1971
+ }
1972
+
1973
+ @Test
1974
+ public void testUpdateTimestampAsInstant() {
1975
+ try (Database db = db()) {
1976
+ db.update("update person set registered=? where name='FRED'") //
1977
+ .parameter(Instant.ofEpochMilli(FRED_REGISTERED_TIME)) //
1978
+ .counts() //
1979
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1980
+ .assertValue(1) //
1981
+ .assertComplete();
1982
+ db.select("select registered from person where name='FRED'") //
1983
+ .getAs(Long.class) //
1984
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1985
+ .assertValue(FRED_REGISTERED_TIME) //
1986
+ .assertComplete();
1987
+ }
1988
+ }
1989
+
1990
+ @Test
1991
+ public void testUpdateTimestampAsZonedDateTime() {
1992
+ try (Database db = db()) {
1993
+ db.update("update person set registered=? where name='FRED'") //
1994
+ .parameter(ZonedDateTime.ofInstant(Instant.ofEpochMilli(FRED_REGISTERED_TIME),
1995
+ ZoneOffset.UTC.normalized())) //
1996
+ .counts() //
1997
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
1998
+ .assertValue(1) //
1999
+ .assertComplete();
2000
+ db.select("select registered from person where name='FRED'") //
2001
+ .getAs(Long.class) //
2002
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
2003
+ .assertValue(FRED_REGISTERED_TIME) //
2004
+ .assertComplete();
2005
+ }
2006
+ }
2007
+
2008
+ @Test
2009
+ public void testCompleteCompletes() {
2010
+ Database db = db(1);
2011
+ db //
2012
+ .update("update person set score=-3 where name='FRED'") //
2013
+ .complete() //
2014
+ .timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
2015
+ .blockingAwait();
2016
+
2017
+ int score = db.select("select score from person where name='FRED'") //
2018
+ .getAs(Integer.class) //
2019
+ .timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
2020
+ .blockingFirst();
2021
+ assertEquals(-3, score);
2022
+ }
2023
+
2024
+ @Test
2025
+ public void testComplete() throws InterruptedException {
2026
+ Database db = db(1);
2027
+ Completable a = db //
2028
+ .update("update person set score=-3 where name='FRED'") //
2029
+ .complete();
2030
+ db.update("update person set score=-4 where score = -3") //
2031
+ .dependsOn(a) //
2032
+ .counts() //
2033
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
2034
+ .assertValue(1) //
2035
+ .assertComplete();
2036
+ }
2037
+
2038
+ @Test
2039
+ public void testCountsOnlyInTransaction() {
2040
+ db().update("update person set score = -3") //
2041
+ .transacted() //
2042
+ .countsOnly() //
2043
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
2044
+ .assertValues(3) //
2045
+ .assertComplete();
2046
+ }
2047
+
2048
+ @Test
2049
+ public void testCountsInTransaction() {
2050
+ db().update("update person set score = -3") //
2051
+ .transacted() //
2052
+ .counts() //
2053
+ .doOnNext(System.out::println) //
2054
+ .toList() //
2055
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
2056
+ .assertValue(list -> list.get(0).isValue() && list.get(0).value() == 3
2057
+ && list.get(1).isComplete() && list.size() == 2) //
2058
+ .assertComplete();
2059
+ }
2060
+
2061
+ @Test
2062
+ public void testTx() throws InterruptedException {
2063
+ Database db = db(3);
2064
+ Single<Tx<?>> transaction = db //
2065
+ .update("update person set score=-3 where name='FRED'") //
2066
+ .transaction();
2067
+
2068
+ transaction //
2069
+ .doOnDispose(() -> log.debug("disposing")) //
2070
+ .doOnSuccess(System.out::println) //
2071
+ .flatMapPublisher(tx -> {
2072
+ log.debug("flatmapping");
2073
+ return tx //
2074
+ .update("update person set score = -4 where score = -3") //
2075
+ .countsOnly() //
2076
+ .doOnSubscribe(s -> log.debug("subscribed")) //
2077
+ .doOnNext(num -> log.debug("num=" + num));
2078
+ }) //
2079
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
2080
+ .assertNoErrors() //
2081
+ .assertValue(1) //
2082
+ .assertComplete();
2083
+ }
2084
+
2085
+ @Test
2086
+ public void testTxAfterSelect() {
2087
+ Database db = db(3);
2088
+ Single<Tx<Integer>> transaction = db //
2089
+ .select("select score from person where name='FRED'") //
2090
+ .transactedValuesOnly() //
2091
+ .getAs(Integer.class) //
2092
+ .firstOrError();
2093
+
2094
+ transaction //
2095
+ .doOnDispose(() -> log.debug("disposing")) //
2096
+ .doOnSuccess(System.out::println) //
2097
+ .flatMapPublisher(tx -> {
2098
+ log.debug("flatmapping");
2099
+ return tx //
2100
+ .update("update person set score = -4 where score = ?") //
2101
+ .parameter(tx.value()) //
2102
+ .countsOnly() //
2103
+ .doOnSubscribe(s -> log.debug("subscribed")) //
2104
+ .doOnNext(num -> log.debug("num=" + num));
2105
+ }) //
2106
+ .test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
2107
+ .assertNoErrors() //
2108
+ .assertValue(1) //
2109
+ .assertComplete();
2110
+ }
2111
+
2112
+ @Test
2113
+ public void testSingleFlatMap() {
2114
+ Single.just(1).flatMapPublisher(n -> Flowable.just(1)).test(1).assertValue(1)
2115
+ .assertComplete();
2116
+ }
2117
+
2118
+ @Test
2119
+ public void testAutomappedInstanceHasMeaningfulToStringMethod() {
2120
+ info();
2121
+ String s = Database.test() //
2122
+ .select("select name, score from person where name=?") //
2123
+ .parameterStream(Flowable.just("FRED")) //
2124
+ .autoMap(Person2.class) //
2125
+ .map(x -> x.toString()) //
2126
+ .blockingSingle();
2127
+ assertEquals("Person2[name=FRED, score=21]", s);
2128
+ }
2129
+
2130
+ @Test
2131
+ public void testAutomappedEquals() {
2132
+ boolean b = Database.test() //
2133
+ .select("select name, score from person where name=?") //
2134
+ .parameterStream(Flowable.just("FRED")) //
2135
+ .autoMap(Person2.class) //
2136
+ .map(x -> x.equals(x)) //
2137
+ .blockingSingle();
2138
+ assertTrue(b);
2139
+ }
2140
+
2141
+ @Test
2142
+ public void testAutomappedDoesNotEqualNull() {
2143
+ boolean b = Database.test() //
2144
+ .select("select name, score from person where name=?") //
2145
+ .parameterStream(Flowable.just("FRED")) //
2146
+ .autoMap(Person2.class) //
2147
+ .map(x -> x.equals(null)) //
2148
+ .blockingSingle();
2149
+ assertFalse(b);
2150
+ }
2151
+
2152
+ @Test
2153
+ public void testAutomappedDoesNotEqual() {
2154
+ boolean b = Database.test() //
2155
+ .select("select name, score from person where name=?") //
2156
+ .parameterStream(Flowable.just("FRED")) //
2157
+ .autoMap(Person2.class) //
2158
+ .map(x -> x.equals(new Object())) //
2159
+ .blockingSingle();
2160
+ assertFalse(b);
2161
+ }
2162
+
2163
+ @Test
2164
+ public void testAutomappedHashCode() {
2165
+ Person2 p = Database.test() //
2166
+ .select("select name, score from person where name=?") //
2167
+ .parameterStream(Flowable.just("FRED")) //
2168
+ .autoMap(Person2.class) //
2169
+ .blockingSingle();
2170
+ assertTrue(p.hashCode() != 0);
2171
+ }
2172
+
2173
+ @Test
2174
+ public void testAutomappedWithParametersThatProvokesMoreThanOneQuery() {
2175
+ Database.test() //
2176
+ .select("select name, score from person where name=?") //
2177
+ .parameters("FRED", "FRED") //
2178
+ .autoMap(Person2.class) //
2179
+ .doOnNext(System.out::println) //
2180
+ .test() //
2181
+ .awaitDone(2000, TimeUnit.SECONDS) //
2182
+ .assertNoErrors() //
2183
+ .assertValueCount(2) //
2184
+ .assertComplete();
2185
+ }
2186
+
2187
+ @Test
2188
+ public void testAutomappedObjectsEqualsAndHashCodeIsDistinctOnValues() {
2189
+ Database.test() //
2190
+ .select("select name, score from person where name=?") //
2191
+ .parameters("FRED", "FRED") //
2192
+ .autoMap(Person2.class) //
2193
+ .distinct() //
2194
+ .doOnNext(System.out::println) //
2195
+ .test() //
2196
+ .awaitDone(2000, TimeUnit.SECONDS) //
2197
+ .assertNoErrors() //
2198
+ .assertValueCount(1) //
2199
+ .assertComplete();
2200
+ }
2201
+
2202
+ @Test
2203
+ public void testAutomappedObjectsEqualsDifferentiatesDifferentInterfacesWithSameMethodNamesAndValues() {
2204
+ PersonDistinct1 p1 = Database.test() //
2205
+ .select("select name, score from person where name=?") //
2206
+ .parameters("FRED") //
2207
+ .autoMap(PersonDistinct1.class) //
2208
+ .blockingFirst();
2209
+
2210
+ PersonDistinct2 p2 = Database.test() //
2211
+ .select("select name, score from person where name=?") //
2212
+ .parameters("FRED") //
2213
+ .autoMap(PersonDistinct2.class) //
2214
+ .blockingFirst();
2215
+
2216
+ assertNotEquals(p1, p2);
2217
+ }
2218
+
2219
+ @Test
2220
+ public void testAutomappedObjectsWhenDefaultMethodInvoked() {
2221
+ PersonWithDefaultMethod p = Database.test() //
2222
+ .select("select name, score from person where name=?") //
2223
+ .parameters("FRED") //
2224
+ .autoMap(PersonWithDefaultMethod.class) //
2225
+ .blockingFirst();
2226
+ assertEquals("fred", p.nameLower());
2227
+ }
2228
+
2229
+ // @Test
2230
+ // public void testDefaultMethod() throws NoSuchMethodException,
2231
+ // IllegalAccessException {
2232
+ // MethodHandles.lookup().findSpecial(PersonWithDefaultMethod.class,
2233
+ // "nameLower",
2234
+ // MethodType.methodType(String.class, new Class[] {}),
2235
+ // PersonWithDefaultMethod.class)
2236
+ //// .bindTo(x);
2237
+ // }
2238
+
2239
+ @Test(expected = AutomappedInterfaceInaccessibleException.class)
2240
+ public void testAutomappedObjectsWhenDefaultMethodInvokedAndIsNonPublicThrows() {
2241
+ PersonWithDefaultMethodNonPublic p = Database.test() //
2242
+ .select("select name, score from person where name=?") //
2243
+ .parameters("FRED") //
2244
+ .autoMap(PersonWithDefaultMethodNonPublic.class) //
2245
+ .blockingFirst();
2246
+ p.nameLower();
2247
+ }
2248
+
2249
+ @Test
2250
+ public void testBlockingDatabase() {
2251
+ Database db = blocking();
2252
+ db.select("select score from person where name=?") //
2253
+ .parameters("FRED", "JOSEPH") //
2254
+ .getAs(Integer.class) //
2255
+ .test() //
2256
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
2257
+ .assertNoErrors() //
2258
+ .assertValues(21, 34) //
2259
+ .assertComplete();
2260
+ }
2261
+
2262
+ @Test
2263
+ public void testBlockingDatabaseTransacted() {
2264
+ Database db = blocking();
2265
+ db.select("select score from person where name=?") //
2266
+ .parameters("FRED", "JOSEPH") //
2267
+ .transactedValuesOnly() //
2268
+ .getAs(Integer.class) //
2269
+ .map(x -> x.value()) //
2270
+ .test() //
2271
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
2272
+ .assertNoErrors() //
2273
+ .assertValues(21, 34) //
2274
+ .assertComplete();
2275
+ }
2276
+
2277
+ @Test
2278
+ public void testBlockingDatabaseTransactedNested() {
2279
+ Database db = blocking();
2280
+ db.select("select score from person where name=?") //
2281
+ .parameters("FRED", "JOSEPH") //
2282
+ .transactedValuesOnly() //
2283
+ .getAs(Integer.class) //
2284
+ .flatMap(tx -> tx.select("select name from person where score=?") //
2285
+ .parameter(tx.value()) //
2286
+ .valuesOnly() //
2287
+ .getAs(String.class))
2288
+ .test() //
2289
+ .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
2290
+ .assertNoErrors() //
2291
+ .assertValues("FRED", "JOSEPH") //
2292
+ .assertComplete();
2293
+ }
2294
+
2295
+ public interface PersonWithDefaultMethod {
2296
+ @Column
2297
+ String name();
2298
+
2299
+ @Column
2300
+ int score();
2301
+
2302
+ public default String nameLower() {
2303
+ return name().toLowerCase();
2304
+ }
2305
+ }
2306
+
2307
+ interface PersonWithDefaultMethodNonPublic {
2308
+ @Column
2309
+ String name();
2310
+
2311
+ @Column
2312
+ int score();
2313
+
2314
+ default String nameLower() {
2315
+ return name().toLowerCase();
2316
+ }
2317
+ }
2318
+
2319
+ interface PersonDistinct1 {
2320
+ @Column
2321
+ String name();
2322
+
2323
+ @Column
2324
+ int score();
2325
+
2326
+ }
2327
+
2328
+ interface PersonDistinct2 {
2329
+ @Column
2330
+ String name();
2331
+
2332
+ @Column
2333
+ int score();
2334
+
2335
+ }
2336
+
2337
+ interface Score {
2338
+ @Column
2339
+ int score();
2340
+ }
2341
+
2342
+ interface Person {
2343
+ @Column
2344
+ String name();
2345
+ }
2346
+
2347
+ interface Person2 {
2348
+ @Column
2349
+ String name();
2350
+
2351
+ @Column
2352
+ int score();
2353
+ }
2354
+
2355
+ interface Person3 {
2356
+ @Column("name")
2357
+ String fullName();
2358
+
2359
+ @Column("score")
2360
+ int examScore();
2361
+ }
2362
+
2363
+ interface Person4 {
2364
+ @Column("namez")
2365
+ String fullName();
2366
+
2367
+ @Column("score")
2368
+ int examScore();
2369
+ }
2370
+
2371
+ interface Person5 {
2372
+ @Index(1)
2373
+ String fullName();
2374
+
2375
+ @Index(2)
2376
+ int examScore();
2377
+ }
2378
+
2379
+ interface Person6 {
2380
+ @Index(1)
2381
+ String fullName();
2382
+
2383
+ @Index(3)
2384
+ int examScore();
2385
+ }
2386
+
2387
+ interface Person7 {
2388
+ @Index(1)
2389
+ String fullName();
2390
+
2391
+ @Index(0)
2392
+ int examScore();
2393
+ }
2394
+
2395
+ interface Person8 {
2396
+ @Column
2397
+ int name();
2398
+ }
2399
+
2400
+ interface Person9 {
2401
+ @Column
2402
+ String name();
2403
+
2404
+ @Index(2)
2405
+ int score();
2406
+ }
2407
+
2408
+ interface PersonNoAnnotation {
2409
+ String name();
2410
+ }
2411
+
2412
+ @Query("select name, score from person order by name")
2413
+ interface Person10 {
2414
+
2415
+ @Column
2416
+ String name();
2417
+
2418
+ @Column
2419
+ int score();
2420
+ }
2421
+
2422
+ }
2423
+
2424
+ ```
2425
+
2426
+ ### Bug Class:
2427
+ PROVER
2428
+
2429
+ ### Kind:
2430
+ ERROR
2431
+
2432
+ ### Bug Type:
2433
+ RESOURCE_LEAK
2434
+
2435
+ ### Qualifier:
2436
+ resource of type `org.davidmoten.rx.jdbc.Database` acquired by call to `db(...)` at line 2012 is not released after line 2017.
2437
+
2438
+ ### Severity:
2439
+ HIGH
2440
+
2441
+ ### Visibility:
2442
+ user
2443
+
2444
+ ### Procedure:
2445
+ void DatabaseTest.testComplete()
2446
+
2447
+ ### Procedure Id:
2448
+ org.davidmoten.rx.jdbc.DatabaseTest.testComplete():void.8e875fdd03f5b5357bf561b3a17ad835
2449
+
2450
+ ### File:
2451
+ src/test/java/org/davidmoten/rx/jdbc/DatabaseTest.java
2452
+
2453
+ ### Key:
2454
+ DatabaseTest.java|testComplete|RESOURCE_LEAK
2455
+
2456
+ ### Node Key:
2457
+ 0dd0b11dc7f32655df35487085033d4e
2458
+
2459
+ ### Hash:
2460
+ 56d795b57b1c2397e3da2d6286723e45
2461
+
2462
+ ### Bug Type Hum:
2463
+ Resource Leak
2464
+
2465
+ ## Task
2466
+
2467
+ Fix the bug in the code.
inferredbugs-11006/instruction.md CHANGED
@@ -244,19 +244,4 @@ Null Dereference
244
 
245
  ## Task
246
 
247
- Analyze the bug information provided above. Your task is to:
248
-
249
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
250
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
251
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
252
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
253
-
254
- ### Analysis Questions:
255
- - What was the specific bug or issue in the original code?
256
- - What scenarios would trigger this bug?
257
- - How does the fix address the root cause?
258
- - Are there any potential edge cases the fix might miss?
259
- - What coding practices could have prevented this bug?
260
- - Are there alternative ways to implement the fix?
261
-
262
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
244
 
245
  ## Task
246
 
247
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-11036/instruction.md CHANGED
@@ -251,19 +251,4 @@ Null Dereference
251
 
252
  ## Task
253
 
254
- Analyze the bug information provided above. Your task is to:
255
-
256
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
257
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
258
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
259
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
260
-
261
- ### Analysis Questions:
262
- - What was the specific bug or issue in the original code?
263
- - What scenarios would trigger this bug?
264
- - How does the fix address the root cause?
265
- - Are there any potential edge cases the fix might miss?
266
- - What coding practices could have prevented this bug?
267
- - Are there alternative ways to implement the fix?
268
-
269
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
251
 
252
  ## Task
253
 
254
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-1114/instruction.md CHANGED
@@ -393,19 +393,4 @@ Dotnet Resource Leak
393
 
394
  ## Task
395
 
396
- Analyze the bug information provided above. Your task is to:
397
-
398
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
399
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
400
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
401
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
402
-
403
- ### Analysis Questions:
404
- - What was the specific bug or issue in the original code?
405
- - What scenarios would trigger this bug?
406
- - How does the fix address the root cause?
407
- - Are there any potential edge cases the fix might miss?
408
- - What coding practices could have prevented this bug?
409
- - Are there alternative ways to implement the fix?
410
-
411
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
393
 
394
  ## Task
395
 
396
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-1326/instruction.md CHANGED
@@ -5185,19 +5185,4 @@ Null Dereference
5185
 
5186
  ## Task
5187
 
5188
- Analyze the bug information provided above. Your task is to:
5189
-
5190
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
5191
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
5192
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
5193
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
5194
-
5195
- ### Analysis Questions:
5196
- - What was the specific bug or issue in the original code?
5197
- - What scenarios would trigger this bug?
5198
- - How does the fix address the root cause?
5199
- - Are there any potential edge cases the fix might miss?
5200
- - What coding practices could have prevented this bug?
5201
- - Are there alternative ways to implement the fix?
5202
-
5203
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
5185
 
5186
  ## Task
5187
 
5188
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-1570/instruction.md CHANGED
@@ -88,19 +88,4 @@ Null Dereference
88
 
89
  ## Task
90
 
91
- Analyze the bug information provided above. Your task is to:
92
-
93
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
94
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
95
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
96
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
97
-
98
- ### Analysis Questions:
99
- - What was the specific bug or issue in the original code?
100
- - What scenarios would trigger this bug?
101
- - How does the fix address the root cause?
102
- - Are there any potential edge cases the fix might miss?
103
- - What coding practices could have prevented this bug?
104
- - Are there alternative ways to implement the fix?
105
-
106
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
88
 
89
  ## Task
90
 
91
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-1579/instruction.md ADDED
@@ -0,0 +1,570 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # InferredBugs Task - Csharp
2
+
3
+ ## Project Information
4
+
5
+ **Project:** CliWrap
6
+ **Bug ID:** 1
7
+ **Language:** csharp
8
+
9
+ ## Bug Information
10
+
11
+ ### File-Level Changes:
12
+
13
+ **Before (Buggy File):**
14
+ ```csharp
15
+ using System;
16
+ using System.Collections.Generic;
17
+ using System.Diagnostics;
18
+ using System.Diagnostics.CodeAnalysis;
19
+ using System.IO;
20
+ using System.Runtime.InteropServices;
21
+ using System.Text;
22
+ using System.Threading;
23
+ using System.Threading.Tasks;
24
+ using CliWrap.Builders;
25
+ using CliWrap.Exceptions;
26
+ using CliWrap.Utils;
27
+ using CliWrap.Utils.Extensions;
28
+
29
+ namespace CliWrap
30
+ {
31
+ /// <summary>
32
+ /// Represents a shell command.
33
+ /// </summary>
34
+ public partial class Command : ICommandConfiguration
35
+ {
36
+ /// <summary>
37
+ /// File path of the executable, batch file, or script, that this command runs on.
38
+ /// </summary>
39
+ public string TargetFilePath { get; }
40
+
41
+ /// <summary>
42
+ /// Arguments passed on the command line.
43
+ /// </summary>
44
+ public string Arguments { get; }
45
+
46
+ /// <summary>
47
+ /// Working directory path.
48
+ /// </summary>
49
+ public string WorkingDirPath { get; }
50
+
51
+ /// <summary>
52
+ /// User credentials set for the underlying process.
53
+ /// </summary>
54
+ public Credentials Credentials { get; }
55
+
56
+ /// <summary>
57
+ /// Environment variables set for the underlying process.
58
+ /// </summary>
59
+ public IReadOnlyDictionary<string, string> EnvironmentVariables { get; }
60
+
61
+ /// <summary>
62
+ /// Configured result validation options.
63
+ /// </summary>
64
+ public CommandResultValidation Validation { get; }
65
+
66
+ /// <summary>
67
+ /// Configured standard input pipe source.
68
+ /// </summary>
69
+ public PipeSource StandardInputPipe { get; }
70
+
71
+ /// <summary>
72
+ /// Configured standard output pipe target.
73
+ /// </summary>
74
+ public PipeTarget StandardOutputPipe { get; }
75
+
76
+ /// <summary>
77
+ /// Configured standard error pipe target.
78
+ /// </summary>
79
+ public PipeTarget StandardErrorPipe { get; }
80
+
81
+ /// <summary>
82
+ /// Initializes an instance of <see cref="Command"/>.
83
+ /// </summary>
84
+ public Command(
85
+ string targetFilePath,
86
+ string arguments,
87
+ string workingDirPath,
88
+ Credentials credentials,
89
+ IReadOnlyDictionary<string, string> environmentVariables,
90
+ CommandResultValidation validation,
91
+ PipeSource standardInputPipe,
92
+ PipeTarget standardOutputPipe,
93
+ PipeTarget standardErrorPipe)
94
+ {
95
+ TargetFilePath = targetFilePath;
96
+ Arguments = arguments;
97
+ WorkingDirPath = workingDirPath;
98
+ Credentials = credentials;
99
+ EnvironmentVariables = environmentVariables;
100
+ Validation = validation;
101
+ StandardInputPipe = standardInputPipe;
102
+ StandardOutputPipe = standardOutputPipe;
103
+ StandardErrorPipe = standardErrorPipe;
104
+ }
105
+
106
+ /// <summary>
107
+ /// Initializes an instance of <see cref="Command"/>.
108
+ /// </summary>
109
+ public Command(string targetFilePath) : this(
110
+ targetFilePath,
111
+ string.Empty,
112
+ Directory.GetCurrentDirectory(),
113
+ Credentials.Default,
114
+ new Dictionary<string, string>(),
115
+ CommandResultValidation.ZeroExitCode,
116
+ PipeSource.Null,
117
+ PipeTarget.Null,
118
+ PipeTarget.Null)
119
+ {
120
+ }
121
+
122
+ /// <summary>
123
+ /// Creates a copy of this command, setting the arguments to the specified value.
124
+ /// </summary>
125
+ public Command WithArguments(string arguments) => new(
126
+ TargetFilePath,
127
+ arguments,
128
+ WorkingDirPath,
129
+ Credentials,
130
+ EnvironmentVariables,
131
+ Validation,
132
+ StandardInputPipe,
133
+ StandardOutputPipe,
134
+ StandardErrorPipe
135
+ );
136
+
137
+ /// <summary>
138
+ /// Creates a copy of this command, setting the arguments to the value configured by the specified delegate.
139
+ /// </summary>
140
+ public Command WithArguments(Action<ArgumentsBuilder> configure)
141
+ {
142
+ var builder = new ArgumentsBuilder();
143
+ configure(builder);
144
+
145
+ return WithArguments(builder.Build());
146
+ }
147
+
148
+ /// <summary>
149
+ /// Creates a copy of this command, setting the arguments to the value obtained by formatting the specified enumeration.
150
+ /// </summary>
151
+ public Command WithArguments(IEnumerable<string> arguments, bool escape) =>
152
+ WithArguments(args => args.Add(arguments, escape));
153
+
154
+ /// <summary>
155
+ /// Creates a copy of this command, setting the arguments to the value obtained by formatting the specified enumeration.
156
+ /// </summary>
157
+ // TODO: (breaking change) remove in favor of optional parameter
158
+ public Command WithArguments(IEnumerable<string> arguments) =>
159
+ WithArguments(arguments, true);
160
+
161
+ /// <summary>
162
+ /// Creates a copy of this command, setting the working directory path to the specified value.
163
+ /// </summary>
164
+ public Command WithWorkingDirectory(string workingDirPath) => new(
165
+ TargetFilePath,
166
+ Arguments,
167
+ workingDirPath,
168
+ Credentials,
169
+ EnvironmentVariables,
170
+ Validation,
171
+ StandardInputPipe,
172
+ StandardOutputPipe,
173
+ StandardErrorPipe
174
+ );
175
+
176
+ /// <summary>
177
+ /// Creates a copy of this command, setting the credentials to the specified value.
178
+ /// </summary>
179
+ public Command WithCredentials(Credentials credentials) => new(
180
+ TargetFilePath,
181
+ Arguments,
182
+ WorkingDirPath,
183
+ credentials,
184
+ EnvironmentVariables,
185
+ Validation,
186
+ StandardInputPipe,
187
+ StandardOutputPipe,
188
+ StandardErrorPipe
189
+ );
190
+
191
+ /// <summary>
192
+ /// Creates a copy of this command, setting the credentials to the value configured by the specified delegate.
193
+ /// </summary>
194
+ public Command WithCredentials(Action<CredentialsBuilder> configure)
195
+ {
196
+ var builder = new CredentialsBuilder();
197
+ configure(builder);
198
+
199
+ return WithCredentials(builder.Build());
200
+ }
201
+
202
+ /// <summary>
203
+ /// Creates a copy of this command, setting the environment variables to the specified value.
204
+ /// </summary>
205
+ public Command WithEnvironmentVariables(IReadOnlyDictionary<string, string> environmentVariables) => new(
206
+ TargetFilePath,
207
+ Arguments,
208
+ WorkingDirPath,
209
+ Credentials,
210
+ environmentVariables,
211
+ Validation,
212
+ StandardInputPipe,
213
+ StandardOutputPipe,
214
+ StandardErrorPipe
215
+ );
216
+
217
+ /// <summary>
218
+ /// Creates a copy of this command, setting the environment variables to the value configured by the specified delegate.
219
+ /// </summary>
220
+ public Command WithEnvironmentVariables(Action<EnvironmentVariablesBuilder> configure)
221
+ {
222
+ var builder = new EnvironmentVariablesBuilder();
223
+ configure(builder);
224
+
225
+ return WithEnvironmentVariables(builder.Build());
226
+ }
227
+
228
+ /// <summary>
229
+ /// Creates a copy of this command, setting the validation options to the specified value.
230
+ /// </summary>
231
+ public Command WithValidation(CommandResultValidation validation) => new(
232
+ TargetFilePath,
233
+ Arguments,
234
+ WorkingDirPath,
235
+ Credentials,
236
+ EnvironmentVariables,
237
+ validation,
238
+ StandardInputPipe,
239
+ StandardOutputPipe,
240
+ StandardErrorPipe
241
+ );
242
+
243
+ /// <summary>
244
+ /// Creates a copy of this command, setting the standard input pipe to the specified source.
245
+ /// </summary>
246
+ public Command WithStandardInputPipe(PipeSource source) => new(
247
+ TargetFilePath,
248
+ Arguments,
249
+ WorkingDirPath,
250
+ Credentials,
251
+ EnvironmentVariables,
252
+ Validation,
253
+ source,
254
+ StandardOutputPipe,
255
+ StandardErrorPipe
256
+ );
257
+
258
+ /// <summary>
259
+ /// Creates a copy of this command, setting the standard output pipe to the specified target.
260
+ /// </summary>
261
+ public Command WithStandardOutputPipe(PipeTarget target) => new(
262
+ TargetFilePath,
263
+ Arguments,
264
+ WorkingDirPath,
265
+ Credentials,
266
+ EnvironmentVariables,
267
+ Validation,
268
+ StandardInputPipe,
269
+ target,
270
+ StandardErrorPipe
271
+ );
272
+
273
+ /// <summary>
274
+ /// Creates a copy of this command, setting the standard error pipe to the specified target.
275
+ /// </summary>
276
+ public Command WithStandardErrorPipe(PipeTarget target) => new(
277
+ TargetFilePath,
278
+ Arguments,
279
+ WorkingDirPath,
280
+ Credentials,
281
+ EnvironmentVariables,
282
+ Validation,
283
+ StandardInputPipe,
284
+ StandardOutputPipe,
285
+ target
286
+ );
287
+
288
+ private ProcessStartInfo GetStartInfo()
289
+ {
290
+ var result = new ProcessStartInfo
291
+ {
292
+ FileName = TargetFilePath,
293
+ Arguments = Arguments,
294
+ WorkingDirectory = WorkingDirPath,
295
+ UserName = Credentials.UserName,
296
+ RedirectStandardInput = true,
297
+ RedirectStandardOutput = true,
298
+ RedirectStandardError = true,
299
+ UseShellExecute = false,
300
+ CreateNoWindow = true,
301
+ };
302
+
303
+ // Domain and password are only supported on Windows
304
+ if (Credentials.Domain is not null || Credentials.Password is not null)
305
+ {
306
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
307
+ {
308
+ result.Domain = Credentials.Domain;
309
+ result.Password = Credentials.Password?.ToSecureString();
310
+ }
311
+ else
312
+ {
313
+ throw new NotSupportedException(
314
+ "Starting a process using a custom domain and password is only supported on Windows."
315
+ );
316
+ }
317
+ }
318
+
319
+ foreach (var (key, value) in EnvironmentVariables)
320
+ result.Environment[key] = value;
321
+
322
+ return result;
323
+ }
324
+
325
+ private async Task PipeStandardInputAsync(ProcessEx process, CancellationToken cancellationToken = default)
326
+ {
327
+ try
328
+ {
329
+ // Some streams do not support cancellation, so we add a fallback that
330
+ // drops the task and returns early.
331
+ // Doing so does leave the original piping task still alive, which is
332
+ // unfortunate, but still better than having everything freeze up.
333
+ // This is important with stdin because the process might finish before
334
+ // the pipe completes, and in case with infinite input stream it would
335
+ // normally result in a deadlock.
336
+ await StandardInputPipe.CopyToAsync(process.StdIn, cancellationToken)
337
+ .WithDangerousCancellation(cancellationToken)
338
+ .ConfigureAwait(false);
339
+ }
340
+ catch (IOException)
341
+ {
342
+ // IOException: The pipe has been ended.
343
+ // This may happen if the process terminated before the pipe could complete.
344
+ // It's not an exceptional situation because the process may not need
345
+ // the entire stdin to complete successfully.
346
+ }
347
+ finally
348
+ {
349
+ await process.StdIn.DisposeAsync().ConfigureAwait(false);
350
+ }
351
+ }
352
+
353
+ private async Task PipeStandardOutputAsync(ProcessEx process, CancellationToken cancellationToken = default)
354
+ {
355
+ try
356
+ {
357
+ await StandardOutputPipe.CopyFromAsync(process.StdOut, cancellationToken)
358
+ .ConfigureAwait(false);
359
+ }
360
+ finally
361
+ {
362
+ await process.StdOut.DisposeAsync().ConfigureAwait(false);
363
+ }
364
+ }
365
+
366
+ private async Task PipeStandardErrorAsync(ProcessEx process, CancellationToken cancellationToken = default)
367
+ {
368
+ try
369
+ {
370
+ await StandardErrorPipe.CopyFromAsync(process.StdErr, cancellationToken)
371
+ .ConfigureAwait(false);
372
+ }
373
+ finally
374
+ {
375
+ await process.StdErr.DisposeAsync().ConfigureAwait(false);
376
+ }
377
+ }
378
+
379
+ private async Task<CommandResult> ExecuteAsync(ProcessEx process, CancellationToken cancellationToken = default)
380
+ {
381
+ // Additional cancellation for stdin in case the process terminates early and doesn't fully exhaust it
382
+ using var stdInCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
383
+
384
+ // Setup and start process
385
+ using var _1 = process;
386
+ process.Start();
387
+ using var _2 = cancellationToken.Register(process.Kill);
388
+
389
+ // Start piping in parallel
390
+ var pipingTask = Task.WhenAll(
391
+ PipeStandardInputAsync(process, stdInCts.Token),
392
+ PipeStandardOutputAsync(process, cancellationToken),
393
+ PipeStandardErrorAsync(process, cancellationToken)
394
+ );
395
+
396
+ // Wait until the process terminates or gets killed
397
+ await process.WaitUntilExitAsync().ConfigureAwait(false);
398
+
399
+ // Cancel stdin in case the process terminated early and doesn't need it anymore
400
+ stdInCts.Cancel();
401
+
402
+ try
403
+ {
404
+ // Wait until piping is done and propagate exceptions
405
+ await pipingTask.ConfigureAwait(false);
406
+ }
407
+ catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
408
+ {
409
+ // Don't throw if cancellation happened internally and not by user request
410
+ }
411
+
412
+ // Validate exit code if required
413
+ if (process.ExitCode != 0 && Validation.IsZeroExitCodeValidationEnabled())
414
+ {
415
+ throw CommandExecutionException.ExitCodeValidation(
416
+ this,
417
+ process.ExitCode
418
+ );
419
+ }
420
+
421
+ return new CommandResult(
422
+ process.ExitCode,
423
+ process.StartTime,
424
+ process.ExitTime
425
+ );
426
+ }
427
+
428
+ /// <summary>
429
+ /// Executes the command asynchronously.
430
+ /// This method can be awaited.
431
+ /// </summary>
432
+ public CommandTask<CommandResult> ExecuteAsync(CancellationToken cancellationToken = default)
433
+ {
434
+ var process = new ProcessEx(GetStartInfo());
435
+ var task = ExecuteAsync(process, cancellationToken);
436
+
437
+ return new CommandTask<CommandResult>(task, process.Id);
438
+ }
439
+
440
+ /// <inheritdoc />
441
+ [ExcludeFromCodeCoverage]
442
+ public override string ToString() => $"{TargetFilePath} {Arguments}";
443
+ }
444
+
445
+ // Pipe operators
446
+ public partial class Command
447
+ {
448
+ /// <summary>
449
+ /// Creates a new command that pipes its standard output to the specified target.
450
+ /// </summary>
451
+ public static Command operator |(Command source, PipeTarget target) =>
452
+ source.WithStandardOutputPipe(target);
453
+
454
+ /// <summary>
455
+ /// Creates a new command that pipes its standard output to the specified stream.
456
+ /// </summary>
457
+ public static Command operator |(Command source, Stream target) =>
458
+ source | PipeTarget.ToStream(target);
459
+
460
+ /// <summary>
461
+ /// Creates a new command that pipes its standard output to the specified string builder.
462
+ /// Uses <see cref="Console.OutputEncoding"/> to decode the string from byte stream.
463
+ /// </summary>
464
+ public static Command operator |(Command source, StringBuilder target) =>
465
+ source | PipeTarget.ToStringBuilder(target);
466
+
467
+ /// <summary>
468
+ /// Creates a new command that pipes its standard output line-by-line to the specified delegate.
469
+ /// Uses <see cref="Console.OutputEncoding"/> to decode the string from byte stream.
470
+ /// </summary>
471
+ public static Command operator |(Command source, Action<string> target) =>
472
+ source | PipeTarget.ToDelegate(target);
473
+
474
+ /// <summary>
475
+ /// Creates a new command that pipes its standard output line-by-line to the specified delegate.
476
+ /// Uses <see cref="Console.OutputEncoding"/> to decode the string from byte stream.
477
+ /// </summary>
478
+ public static Command operator |(Command source, Func<string, Task> target) =>
479
+ source | PipeTarget.ToDelegate(target);
480
+
481
+ /// <summary>
482
+ /// Creates a new command that pipes its standard output and standard error to the specified targets.
483
+ /// </summary>
484
+ public static Command operator |(Command source, ValueTuple<PipeTarget, PipeTarget> target) =>
485
+ source
486
+ .WithStandardOutputPipe(target.Item1)
487
+ .WithStandardErrorPipe(target.Item2);
488
+
489
+ /// <summary>
490
+ /// Creates a new command that pipes its standard output and standard error to the specified streams.
491
+ /// </summary>
492
+ public static Command operator |(Command source, ValueTuple<Stream, Stream> target) =>
493
+ source | (PipeTarget.ToStream(target.Item1), PipeTarget.ToStream(target.Item2));
494
+
495
+ /// <summary>
496
+ /// Creates a new command that pipes its standard output and standard error to the specified string builders.
497
+ /// Uses <see cref="Console.OutputEncoding"/> to decode the string from byte stream.
498
+ /// </summary>
499
+ public static Command operator |(Command source, ValueTuple<StringBuilder, StringBuilder> target) =>
500
+ source | (PipeTarget.ToStringBuilder(target.Item1), PipeTarget.ToStringBuilder(target.Item2));
501
+
502
+ /// <summary>
503
+ /// Creates a new command that pipes its standard output and standard error line-by-line to the specified delegates.
504
+ /// Uses <see cref="Console.OutputEncoding"/> to decode the strings from byte streams.
505
+ /// </summary>
506
+ public static Command operator |(Command source, ValueTuple<Action<string>, Action<string>> target) =>
507
+ source | (PipeTarget.ToDelegate(target.Item1), PipeTarget.ToDelegate(target.Item2));
508
+
509
+ /// <summary>
510
+ /// Creates a new command that pipes its standard output and standard error line-by-line to the specified delegates.
511
+ /// Uses <see cref="Console.OutputEncoding"/> to decode the strings from byte streams.
512
+ /// </summary>
513
+ public static Command operator |(Command source, ValueTuple<Func<string, Task>, Func<string, Task>> target) =>
514
+ source | (PipeTarget.ToDelegate(target.Item1), PipeTarget.ToDelegate(target.Item2));
515
+
516
+ /// <summary>
517
+ /// Creates a new command that pipes its standard input from the specified source.
518
+ /// </summary>
519
+ public static Command operator |(PipeSource source, Command target) =>
520
+ target.WithStandardInputPipe(source);
521
+
522
+ /// <summary>
523
+ /// Creates a new command that pipes its standard input from the specified stream.
524
+ /// </summary>
525
+ public static Command operator |(Stream source, Command target) =>
526
+ PipeSource.FromStream(source) | target;
527
+
528
+ /// <summary>
529
+ /// Creates a new command that pipes its standard input from the specified string.
530
+ /// Uses <see cref="Console.InputEncoding"/> to encode the string into byte stream.
531
+ /// </summary>
532
+ public static Command operator |(string source, Command target) =>
533
+ PipeSource.FromString(source) | target;
534
+
535
+ /// <summary>
536
+ /// Creates a new command that pipes its standard input from the standard output of the specified other command.
537
+ /// </summary>
538
+ public static Command operator |(Command source, Command target) =>
539
+ PipeSource.FromCommand(source) | target;
540
+ }
541
+ }
542
+ ```
543
+
544
+ ### Bug Type:
545
+ DOTNET_RESOURCE_LEAK
546
+
547
+ ### Qualifier:
548
+ Leaked resource (returned from System.Security.SecureString CliWrap.Utils.Extensions.StringExtensions::ToSecureString(System.String) at Line 295) of type System.Security.SecureString in method "ProcessStartInfo Command.GetStartInfo()".
549
+
550
+ ### Severity:
551
+ ERROR
552
+
553
+ ### Procedure:
554
+ ProcessStartInfo Command.GetStartInfo()
555
+
556
+ ### File:
557
+ CliWrap/Command.cs
558
+
559
+ ### Key:
560
+ Command.cs|GetStartInfo|DOTNET_RESOURCE_LEAK
561
+
562
+ ### Hash:
563
+ 7a33454b8cbeef67d47f4ca6276cc620
564
+
565
+ ### Bug Type Hum:
566
+ Dotnet Resource Leak
567
+
568
+ ## Task
569
+
570
+ Fix the bug in the code.
inferredbugs-1742/instruction.md ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # InferredBugs Task - Csharp
2
+
3
+ ## Project Information
4
+
5
+ **Project:** netmq
6
+ **Bug ID:** 8
7
+ **Language:** csharp
8
+
9
+ ## Bug Information
10
+
11
+ ### File-Level Changes:
12
+
13
+ **Before (Buggy File):**
14
+ ```csharp
15
+ using System;
16
+ using System.Collections.Generic;
17
+ using System.Linq;
18
+ using System.Security.Cryptography;
19
+ using System.Security.Cryptography.X509Certificates;
20
+ using System.Text;
21
+ using NUnit.Framework;
22
+ using NetMQ.Security;
23
+ using NetMQ.Security.V0_1;
24
+
25
+ namespace NetMQ.Tests
26
+ {
27
+ [TestFixture]
28
+ class SecurityTests
29
+ {
30
+ private void DoHandshake(out SecureChannel clientSecureChannel,
31
+ out SecureChannel serverSecureChannel)
32
+ {
33
+ X509Certificate2 certificate = new X509Certificate2("NetMQ.Testing.pfx", "1");
34
+
35
+ serverSecureChannel = new SecureChannel(ConnectionEnd.Server);
36
+ serverSecureChannel.Certificate = certificate;
37
+
38
+ clientSecureChannel = new SecureChannel(ConnectionEnd.Client);
39
+
40
+ IList<NetMQMessage> clientOutgoingMessages = new List<NetMQMessage>();
41
+ IList<NetMQMessage> serverOutgoingMessages = new List<NetMQMessage>();
42
+
43
+ bool serverComplete = false;
44
+
45
+ bool clientComplete = clientSecureChannel.ProcessMessage(null, clientOutgoingMessages);
46
+
47
+ while (!serverComplete || !clientComplete)
48
+ {
49
+ if (!serverComplete)
50
+ {
51
+ foreach (var message in clientOutgoingMessages)
52
+ {
53
+ serverComplete = serverSecureChannel.ProcessMessage(message, serverOutgoingMessages);
54
+
55
+ if (serverComplete)
56
+ {
57
+ break;
58
+ }
59
+ }
60
+
61
+ clientOutgoingMessages.Clear();
62
+ }
63
+
64
+ if (!clientComplete)
65
+ {
66
+ foreach (var message in serverOutgoingMessages)
67
+ {
68
+ clientComplete = clientSecureChannel.ProcessMessage(message, clientOutgoingMessages);
69
+
70
+ if (clientComplete)
71
+ {
72
+ break;
73
+ }
74
+ }
75
+
76
+ serverOutgoingMessages.Clear();
77
+ }
78
+ }
79
+ }
80
+
81
+ [Test]
82
+ public void Encrypt()
83
+ {
84
+ SecureChannel clientSecureChannel;
85
+ SecureChannel serverSecureChannel;
86
+
87
+ DoHandshake(out clientSecureChannel, out serverSecureChannel);
88
+
89
+ string text = "hellohello-hello1";
90
+
91
+ NetMQMessage message = new NetMQMessage();
92
+ message.Append(text);
93
+
94
+ NetMQMessage encryptedMessage = clientSecureChannel.EncryptApplicationMessage(message);
95
+
96
+ NetMQMessage dycryptedMessage = serverSecureChannel.DecryptApplicationMessage(encryptedMessage);
97
+
98
+ string result = dycryptedMessage[0].ConvertToString();
99
+
100
+ Assert.AreEqual(text, result);
101
+ }
102
+
103
+ [Test]
104
+ public void Handshake()
105
+ {
106
+
107
+
108
+ }
109
+
110
+ }
111
+ }
112
+
113
+ ```
114
+
115
+ ### Bug Type:
116
+ DOTNET_RESOURCE_LEAK
117
+
118
+ ### Qualifier:
119
+ Leaked resource certificate of type System.Security.Cryptography.X509Certificates.X509Certificate2 in method "Void SecurityTests.DoHandshake(SecureChannel&,SecureChannel&)".
120
+
121
+ ### Severity:
122
+ ERROR
123
+
124
+ ### Procedure:
125
+ Void SecurityTests.DoHandshake(SecureChannel&,SecureChannel&)
126
+
127
+ ### File:
128
+ src/NetMQ.Tests/SecurityTests.cs
129
+
130
+ ### Key:
131
+ SecurityTests.cs|DoHandshake|DOTNET_RESOURCE_LEAK
132
+
133
+ ### Hash:
134
+ 8e23b8dcb68237092d1e5d5355328e24
135
+
136
+ ### Bug Type Hum:
137
+ Dotnet Resource Leak
138
+
139
+ ## Task
140
+
141
+ Fix the bug in the code.
inferredbugs-1921/instruction.md CHANGED
@@ -2304,19 +2304,4 @@ Null Dereference
2304
 
2305
  ## Task
2306
 
2307
- Analyze the bug information provided above. Your task is to:
2308
-
2309
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
2310
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
2311
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
2312
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
2313
-
2314
- ### Analysis Questions:
2315
- - What was the specific bug or issue in the original code?
2316
- - What scenarios would trigger this bug?
2317
- - How does the fix address the root cause?
2318
- - Are there any potential edge cases the fix might miss?
2319
- - What coding practices could have prevented this bug?
2320
- - Are there alternative ways to implement the fix?
2321
-
2322
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
2304
 
2305
  ## Task
2306
 
2307
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-1928/instruction.md CHANGED
@@ -2506,19 +2506,4 @@ Null Dereference
2506
 
2507
  ## Task
2508
 
2509
- Analyze the bug information provided above. Your task is to:
2510
-
2511
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
2512
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
2513
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
2514
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
2515
-
2516
- ### Analysis Questions:
2517
- - What was the specific bug or issue in the original code?
2518
- - What scenarios would trigger this bug?
2519
- - How does the fix address the root cause?
2520
- - Are there any potential edge cases the fix might miss?
2521
- - What coding practices could have prevented this bug?
2522
- - Are there alternative ways to implement the fix?
2523
-
2524
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
2506
 
2507
  ## Task
2508
 
2509
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-2308/instruction.md CHANGED
@@ -594,19 +594,4 @@ Dotnet Resource Leak
594
 
595
  ## Task
596
 
597
- Analyze the bug information provided above. Your task is to:
598
-
599
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
600
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
601
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
602
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
603
-
604
- ### Analysis Questions:
605
- - What was the specific bug or issue in the original code?
606
- - What scenarios would trigger this bug?
607
- - How does the fix address the root cause?
608
- - Are there any potential edge cases the fix might miss?
609
- - What coding practices could have prevented this bug?
610
- - Are there alternative ways to implement the fix?
611
-
612
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
594
 
595
  ## Task
596
 
597
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-2338/instruction.md CHANGED
@@ -148,19 +148,4 @@ Null Dereference
148
 
149
  ## Task
150
 
151
- Analyze the bug information provided above. Your task is to:
152
-
153
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
154
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
155
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
156
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
157
-
158
- ### Analysis Questions:
159
- - What was the specific bug or issue in the original code?
160
- - What scenarios would trigger this bug?
161
- - How does the fix address the root cause?
162
- - Are there any potential edge cases the fix might miss?
163
- - What coding practices could have prevented this bug?
164
- - Are there alternative ways to implement the fix?
165
-
166
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
148
 
149
  ## Task
150
 
151
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-2557/instruction.md CHANGED
@@ -142,19 +142,4 @@ Dotnet Resource Leak
142
 
143
  ## Task
144
 
145
- Analyze the bug information provided above. Your task is to:
146
-
147
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
148
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
149
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
150
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
151
-
152
- ### Analysis Questions:
153
- - What was the specific bug or issue in the original code?
154
- - What scenarios would trigger this bug?
155
- - How does the fix address the root cause?
156
- - Are there any potential edge cases the fix might miss?
157
- - What coding practices could have prevented this bug?
158
- - Are there alternative ways to implement the fix?
159
-
160
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
142
 
143
  ## Task
144
 
145
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-2764/instruction.md CHANGED
@@ -73,19 +73,4 @@ Uninitialized Value
73
 
74
  ## Task
75
 
76
- Analyze the bug information provided above. Your task is to:
77
-
78
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
79
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
80
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
81
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
82
-
83
- ### Analysis Questions:
84
- - What was the specific bug or issue in the original code?
85
- - What scenarios would trigger this bug?
86
- - How does the fix address the root cause?
87
- - Are there any potential edge cases the fix might miss?
88
- - What coding practices could have prevented this bug?
89
- - Are there alternative ways to implement the fix?
90
-
91
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
73
 
74
  ## Task
75
 
76
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-2765/instruction.md CHANGED
@@ -352,19 +352,4 @@ Uninitialized Value
352
 
353
  ## Task
354
 
355
- Analyze the bug information provided above. Your task is to:
356
-
357
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
358
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
359
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
360
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
361
-
362
- ### Analysis Questions:
363
- - What was the specific bug or issue in the original code?
364
- - What scenarios would trigger this bug?
365
- - How does the fix address the root cause?
366
- - Are there any potential edge cases the fix might miss?
367
- - What coding practices could have prevented this bug?
368
- - Are there alternative ways to implement the fix?
369
-
370
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
352
 
353
  ## Task
354
 
355
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-2791/instruction.md ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # InferredBugs Task - Csharp
2
+
3
+ ## Project Information
4
+
5
+ **Project:** couchbase-net-client
6
+ **Bug ID:** 18
7
+ **Language:** csharp
8
+
9
+ ## Bug Information
10
+
11
+ ### File-Level Changes:
12
+
13
+ **Before (Buggy File):**
14
+ ```csharp
15
+ using Common.Logging;
16
+ using Couchbase.Authentication.SASL;
17
+ using Couchbase.Configuration;
18
+ using Couchbase.Configuration.Client;
19
+ using Couchbase.Configuration.Server.Providers;
20
+ using Couchbase.Configuration.Server.Providers.CarrierPublication;
21
+ using Couchbase.Configuration.Server.Providers.Streaming;
22
+ using Couchbase.Configuration.Server.Serialization;
23
+ using Couchbase.Core.Buckets;
24
+ using Couchbase.IO;
25
+ using Couchbase.IO.Strategies;
26
+ using Couchbase.IO.Strategies.Async;
27
+ using System;
28
+ using System.Collections.Concurrent;
29
+ using System.Collections.Generic;
30
+ using System.Linq;
31
+ using System.Net;
32
+ using System.Security.Authentication;
33
+
34
+ namespace Couchbase.Core
35
+ {
36
+ internal sealed class ClusterManager : IClusterManager
37
+ {
38
+ private readonly static ILog Log = LogManager.GetCurrentClassLogger();
39
+ private readonly ClientConfiguration _clientConfig;
40
+ private readonly ConcurrentDictionary<string, IBucket> _buckets = new ConcurrentDictionary<string, IBucket>();
41
+ private readonly List<IConfigProvider> _configProviders = new List<IConfigProvider>();
42
+ private readonly Func<IConnectionPool, ISaslMechanism, IOStrategy> _ioStrategyFactory;
43
+ private readonly Func<PoolConfiguration, IPEndPoint, IConnectionPool> _connectionPoolFactory;
44
+ private readonly Func<string, string, IOStrategy, ISaslMechanism> _saslFactory;
45
+ private bool _disposed;
46
+
47
+ public ClusterManager(ClientConfiguration clientConfig)
48
+ : this(clientConfig,
49
+ (pool, sm) => new DefaultIOStrategy(pool, sm),
50
+ (config, endpoint) =>
51
+ {
52
+ IConnectionPool connectionPool = null;
53
+ if (config.EncryptTraffic)
54
+ {
55
+ connectionPool = new ConnectionPool<SslConnection>(config, endpoint);
56
+ }
57
+ else
58
+ {
59
+ connectionPool = new ConnectionPool<EapConnection>(config, endpoint);
60
+ }
61
+ return connectionPool;
62
+ },
63
+ SaslFactory.GetFactory3())
64
+ {
65
+ }
66
+
67
+ public ClusterManager(ClientConfiguration clientConfig, Func<IConnectionPool, ISaslMechanism, IOStrategy> ioStrategyFactory)
68
+ : this(clientConfig,
69
+ ioStrategyFactory,
70
+ (config, endpoint) =>
71
+ {
72
+ IConnectionPool connectionPool = null;
73
+ if (config.EncryptTraffic)
74
+ {
75
+ connectionPool = new ConnectionPool<SslConnection>(config, endpoint);
76
+ }
77
+ else
78
+ {
79
+ connectionPool = new ConnectionPool<EapConnection>(config, endpoint);
80
+ }
81
+ return connectionPool;
82
+ }, SaslFactory.GetFactory3())
83
+ {
84
+ }
85
+
86
+ public ClusterManager(ClientConfiguration clientConfig, Func<IConnectionPool, ISaslMechanism, IOStrategy> ioStrategyFactory, Func<PoolConfiguration, IPEndPoint, IConnectionPool> connectionPoolFactory, Func<string, string, IOStrategy, ISaslMechanism> saslFactory)
87
+ {
88
+ _clientConfig = clientConfig;
89
+ _ioStrategyFactory = ioStrategyFactory;
90
+ _connectionPoolFactory = connectionPoolFactory;
91
+ _saslFactory = saslFactory;
92
+ Initialize();
93
+ }
94
+
95
+ public List<IConfigProvider> ConfigProviders { get { return _configProviders; } }
96
+
97
+ //TODO possibly make providers instantiation configurable...maybe. perhaps.
98
+ private void Initialize()
99
+ {
100
+ //_configProviders.Add(new CarrierPublicationProvider(_clientConfig, _ioStrategyFactory, _connectionPoolFactory, _saslFactory));
101
+ _configProviders.Add(new HttpStreamingProvider(_clientConfig, _ioStrategyFactory, _connectionPoolFactory, _saslFactory));
102
+ }
103
+
104
+ public IConfigProvider GetProvider(string name)
105
+ {
106
+ throw new NotImplementedException();
107
+ }
108
+
109
+ public IBucket CreateBucket(string bucketName)
110
+ {
111
+ return CreateBucket(bucketName, string.Empty);
112
+ }
113
+
114
+ public IBucket CreateBucket(string bucketName, string password)
115
+ {
116
+ //note we probably want to treat this whole process as an aggregate and not log
117
+ //until the process has completed with success or failure then logged along with
118
+ //the sequence of events that occurred.
119
+ var success = false;
120
+ IBucket bucket = null;
121
+ foreach (var provider in _configProviders)
122
+ {
123
+ try
124
+ {
125
+ Log.DebugFormat("Trying to boostrap with {0}.", provider);
126
+ var config = provider.GetConfig(bucketName, password);
127
+ switch (config.NodeLocator)
128
+ {
129
+ case NodeLocatorEnum.VBucket:
130
+ bucket = new CouchbaseBucket(this, bucketName);
131
+ break;
132
+
133
+ case NodeLocatorEnum.Ketama:
134
+ bucket = new MemcachedBucket(this, bucketName);
135
+ break;
136
+
137
+ default:
138
+ throw new ArgumentOutOfRangeException();
139
+ }
140
+
141
+ var configObserver = bucket as IConfigObserver;
142
+ if (provider.ObserverExists(configObserver))
143
+ {
144
+ Log.DebugFormat("Using existing bootstrap {0}.", provider);
145
+ configObserver.NotifyConfigChanged(config);
146
+ success = true;
147
+ break;
148
+ }
149
+ if (provider.RegisterObserver(configObserver) &&
150
+ _buckets.TryAdd(bucket.Name, bucket))
151
+ {
152
+ Log.DebugFormat("Successfully boostrap using {0}.", provider);
153
+ configObserver.NotifyConfigChanged(config);
154
+ success = true;
155
+ break;
156
+ }
157
+ }
158
+ catch (BucketNotFoundException e)
159
+ {
160
+ Log.Warn(e);
161
+ }
162
+ catch (ConfigException e)
163
+ {
164
+ Log.Warn(e);
165
+ }
166
+ catch (AuthenticationException e)
167
+ {
168
+ Log.Warn(e);
169
+ break;
170
+ }
171
+ }
172
+
173
+ if (!success)
174
+ {
175
+ throw new ConfigException("Could not bootstrap {0}. See log for details.", bucketName);
176
+ }
177
+ return bucket;
178
+ }
179
+
180
+ public void NotifyConfigPublished(IBucketConfig bucketConfig)
181
+ {
182
+ var provider = _configProviders.FirstOrDefault(x => x is CarrierPublicationProvider);
183
+ if (provider != null)
184
+ {
185
+ var carrierPublicationProvider = provider as CarrierPublicationProvider;
186
+ if (carrierPublicationProvider != null)
187
+ {
188
+ carrierPublicationProvider.UpdateConfig(bucketConfig);
189
+ }
190
+ }
191
+ }
192
+
193
+ public void DestroyBucket(IBucket bucket)
194
+ {
195
+ IBucket temp;
196
+ if (_buckets.TryRemove(bucket.Name, out temp))
197
+ {
198
+ var configObserver = temp as IConfigObserver;
199
+ foreach (var configProvider in ConfigProviders)
200
+ {
201
+ configProvider.UnRegisterObserver(configObserver);
202
+ }
203
+ }
204
+ }
205
+
206
+ public void Dispose()
207
+ {
208
+ Dispose(true);
209
+ }
210
+
211
+ public void Dispose(bool disposing)
212
+ {
213
+ if (!_disposed)
214
+ {
215
+ if (disposing)
216
+ {
217
+ GC.SuppressFinalize(this);
218
+ }
219
+ foreach (var pair in _buckets)
220
+ {
221
+ DestroyBucket(pair.Value);
222
+ }
223
+ _disposed = true;
224
+ }
225
+ }
226
+
227
+ ~ClusterManager()
228
+ {
229
+ Dispose(false);
230
+ }
231
+ }
232
+ }
233
+
234
+ #region [ License information ]
235
+
236
+ /* ************************************************************
237
+ *
238
+ * @author Couchbase <info@couchbase.com>
239
+ * @copyright 2014 Couchbase, Inc.
240
+ *
241
+ * Licensed under the Apache License, Version 2.0 (the "License");
242
+ * you may not use this file except in compliance with the License.
243
+ * You may obtain a copy of the License at
244
+ *
245
+ * http://www.apache.org/licenses/LICENSE-2.0
246
+ *
247
+ * Unless required by applicable law or agreed to in writing, software
248
+ * distributed under the License is distributed on an "AS IS" BASIS,
249
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
250
+ * See the License for the specific language governing permissions and
251
+ * limitations under the License.
252
+ *
253
+ * ************************************************************/
254
+
255
+ #endregion
256
+
257
+ ```
258
+
259
+ ### Bug Type:
260
+ DOTNET_RESOURCE_LEAK
261
+
262
+ ### Qualifier:
263
+ Leaked resource (output of Couchbase.Configuration.Server.Providers.Streaming.HttpStreamingProvider::.ctor() at Line 87) of type Couchbase.Configuration.Server.Providers.Streaming.HttpStreamingProvider in method "Void ClusterManager.Initialize()".
264
+
265
+ ### Severity:
266
+ ERROR
267
+
268
+ ### Procedure:
269
+ Void ClusterManager.Initialize()
270
+
271
+ ### File:
272
+ Src/Couchbase/Core/ClusterManager.cs
273
+
274
+ ### Key:
275
+ ClusterManager.cs|Initialize|DOTNET_RESOURCE_LEAK
276
+
277
+ ### Hash:
278
+ c21e99b052315c5eb0e5503ccbb555a4
279
+
280
+ ### Bug Type Hum:
281
+ Dotnet Resource Leak
282
+
283
+ ## Task
284
+
285
+ Fix the bug in the code.
inferredbugs-2906/instruction.md ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # InferredBugs Task - Java
2
+
3
+ ## Project Information
4
+
5
+ **Project:** ShiroJwt
6
+ **Bug ID:** 2
7
+ **Language:** java
8
+
9
+ ## Bug Information
10
+
11
+ ### File-Level Changes:
12
+
13
+ **Before (Buggy File):**
14
+ ```java
15
+ package com.wang.config.shiro.cache;
16
+
17
+ import com.wang.util.JwtUtil;
18
+ import com.wang.util.JedisUtil;
19
+ import com.wang.model.common.Constant;
20
+ import com.wang.util.common.PropertiesUtil;
21
+ import com.wang.util.common.SerializableUtil;
22
+ import org.apache.shiro.cache.Cache;
23
+ import org.apache.shiro.cache.CacheException;
24
+
25
+ import java.util.*;
26
+
27
+ /**
28
+ * 重写Shiro的Cache保存读取
29
+ * @author Wang926454
30
+ * @date 2018/9/4 17:31
31
+ */
32
+ public class CustomCache<K,V> implements Cache<K,V> {
33
+
34
+ /**
35
+ * 缓存的key名称获取为shiro:cache:account
36
+ * @param key
37
+ * @return java.lang.String
38
+ * @author Wang926454
39
+ * @date 2018/9/4 18:33
40
+ */
41
+ private String getKey(Object key) {
42
+ return Constant.PREFIX_SHIRO_CACHE + JwtUtil.getClaim(key.toString(), Constant.ACCOUNT);
43
+ }
44
+
45
+ /**
46
+ * 获取缓存
47
+ */
48
+ @Override
49
+ public Object get(Object key) throws CacheException {
50
+ if(!JedisUtil.exists(this.getKey(key))){
51
+ return null;
52
+ }
53
+ return JedisUtil.getObject(this.getKey(key));
54
+ }
55
+
56
+ /**
57
+ * 保存缓存
58
+ */
59
+ @Override
60
+ public Object put(Object key, Object value) throws CacheException {
61
+ // 读取配置文件,获取Redis的Shiro缓存过期时间
62
+ PropertiesUtil.readProperties("config.properties");
63
+ String shiroCacheExpireTime = PropertiesUtil.getProperty("shiroCacheExpireTime");
64
+ // 设置Redis的Shiro缓存
65
+ return JedisUtil.setObject(this.getKey(key), value, Integer.parseInt(shiroCacheExpireTime));
66
+ }
67
+
68
+ /**
69
+ * 移除缓存
70
+ */
71
+ @Override
72
+ public Object remove(Object key) throws CacheException {
73
+ if(!JedisUtil.exists(this.getKey(key))){
74
+ return null;
75
+ }
76
+ JedisUtil.delKey(this.getKey(key));
77
+ return null;
78
+ }
79
+
80
+ /**
81
+ * 清空所有缓存
82
+ */
83
+ @Override
84
+ public void clear() throws CacheException {
85
+ JedisUtil.getJedis().flushDB();
86
+ }
87
+
88
+ /**
89
+ * 缓存的个数
90
+ */
91
+ @Override
92
+ public int size() {
93
+ Long size = JedisUtil.getJedis().dbSize();
94
+ return size.intValue();
95
+ }
96
+
97
+ /**
98
+ * 获取所有的key
99
+ */
100
+ @Override
101
+ public Set keys() {
102
+ Set<byte[]> keys = JedisUtil.getJedis().keys(new String("*").getBytes());
103
+ Set<Object> set = new HashSet<Object>();
104
+ for (byte[] bs : keys) {
105
+ set.add(SerializableUtil.unserializable(bs));
106
+ }
107
+ return set;
108
+ }
109
+
110
+ /**
111
+ * 获取所有的value
112
+ */
113
+ @Override
114
+ public Collection values() {
115
+ Set keys = this.keys();
116
+ List<Object> values = new ArrayList<Object>();
117
+ for (Object key : keys) {
118
+ values.add(JedisUtil.getObject(this.getKey(key)));
119
+ }
120
+ return values;
121
+ }
122
+ }
123
+
124
+ ```
125
+
126
+ ### Bug Class:
127
+ PROVER
128
+
129
+ ### Kind:
130
+ ERROR
131
+
132
+ ### Bug Type:
133
+ NULL_DEREFERENCE
134
+
135
+ ### Qualifier:
136
+ object returned by `getJedis()` could be null and is dereferenced at line 71.
137
+
138
+ ### Severity:
139
+ HIGH
140
+
141
+ ### Visibility:
142
+ user
143
+
144
+ ### Procedure:
145
+ void CustomCache.clear()
146
+
147
+ ### Procedure Id:
148
+ com.wang.config.shiro.cache.CustomCache.clear():void.5d6055720bf4779284e68e83ceaa6608
149
+
150
+ ### File:
151
+ src/main/java/com/wang/config/shiro/cache/CustomCache.java
152
+
153
+ ### Key:
154
+ CustomCache.java|clear|NULL_DEREFERENCE
155
+
156
+ ### Node Key:
157
+ f17711d6e64f2c443a0f2eb1b1bb0871
158
+
159
+ ### Hash:
160
+ d05900a21e0cdaf409f251f46dcd9b2c
161
+
162
+ ### Bug Type Hum:
163
+ Null Dereference
164
+
165
+ ## Task
166
+
167
+ Fix the bug in the code.
inferredbugs-2936/instruction.md CHANGED
@@ -1003,19 +1003,4 @@ Thread Safety Violation
1003
 
1004
  ## Task
1005
 
1006
- Analyze the bug information provided above. Your task is to:
1007
-
1008
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
1009
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
1010
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
1011
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
1012
-
1013
- ### Analysis Questions:
1014
- - What was the specific bug or issue in the original code?
1015
- - What scenarios would trigger this bug?
1016
- - How does the fix address the root cause?
1017
- - Are there any potential edge cases the fix might miss?
1018
- - What coding practices could have prevented this bug?
1019
- - Are there alternative ways to implement the fix?
1020
-
1021
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
1003
 
1004
  ## Task
1005
 
1006
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-3015/instruction.md CHANGED
@@ -325,19 +325,4 @@ Resource Leak
325
 
326
  ## Task
327
 
328
- Analyze the bug information provided above. Your task is to:
329
-
330
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
331
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
332
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
333
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
334
-
335
- ### Analysis Questions:
336
- - What was the specific bug or issue in the original code?
337
- - What scenarios would trigger this bug?
338
- - How does the fix address the root cause?
339
- - Are there any potential edge cases the fix might miss?
340
- - What coding practices could have prevented this bug?
341
- - Are there alternative ways to implement the fix?
342
-
343
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
325
 
326
  ## Task
327
 
328
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-3227/instruction.md CHANGED
@@ -183,19 +183,4 @@ Null Dereference
183
 
184
  ## Task
185
 
186
- Analyze the bug information provided above. Your task is to:
187
-
188
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
189
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
190
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
191
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
192
-
193
- ### Analysis Questions:
194
- - What was the specific bug or issue in the original code?
195
- - What scenarios would trigger this bug?
196
- - How does the fix address the root cause?
197
- - Are there any potential edge cases the fix might miss?
198
- - What coding practices could have prevented this bug?
199
- - Are there alternative ways to implement the fix?
200
-
201
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
183
 
184
  ## Task
185
 
186
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-3471/instruction.md CHANGED
@@ -246,19 +246,4 @@ Resource Leak
246
 
247
  ## Task
248
 
249
- Analyze the bug information provided above. Your task is to:
250
-
251
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
252
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
253
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
254
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
255
-
256
- ### Analysis Questions:
257
- - What was the specific bug or issue in the original code?
258
- - What scenarios would trigger this bug?
259
- - How does the fix address the root cause?
260
- - Are there any potential edge cases the fix might miss?
261
- - What coding practices could have prevented this bug?
262
- - Are there alternative ways to implement the fix?
263
-
264
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
246
 
247
  ## Task
248
 
249
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-3478/instruction.md CHANGED
@@ -189,19 +189,4 @@ Null Dereference
189
 
190
  ## Task
191
 
192
- Analyze the bug information provided above. Your task is to:
193
-
194
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
195
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
196
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
197
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
198
-
199
- ### Analysis Questions:
200
- - What was the specific bug or issue in the original code?
201
- - What scenarios would trigger this bug?
202
- - How does the fix address the root cause?
203
- - Are there any potential edge cases the fix might miss?
204
- - What coding practices could have prevented this bug?
205
- - Are there alternative ways to implement the fix?
206
-
207
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
189
 
190
  ## Task
191
 
192
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-3484/instruction.md CHANGED
@@ -440,19 +440,4 @@ Resource Leak
440
 
441
  ## Task
442
 
443
- Analyze the bug information provided above. Your task is to:
444
-
445
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
446
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
447
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
448
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
449
-
450
- ### Analysis Questions:
451
- - What was the specific bug or issue in the original code?
452
- - What scenarios would trigger this bug?
453
- - How does the fix address the root cause?
454
- - Are there any potential edge cases the fix might miss?
455
- - What coding practices could have prevented this bug?
456
- - Are there alternative ways to implement the fix?
457
-
458
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
440
 
441
  ## Task
442
 
443
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-3485/instruction.md CHANGED
@@ -348,19 +348,4 @@ Thread Safety Violation
348
 
349
  ## Task
350
 
351
- Analyze the bug information provided above. Your task is to:
352
-
353
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
354
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
355
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
356
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
357
-
358
- ### Analysis Questions:
359
- - What was the specific bug or issue in the original code?
360
- - What scenarios would trigger this bug?
361
- - How does the fix address the root cause?
362
- - Are there any potential edge cases the fix might miss?
363
- - What coding practices could have prevented this bug?
364
- - Are there alternative ways to implement the fix?
365
-
366
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
348
 
349
  ## Task
350
 
351
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-3643/instruction.md CHANGED
@@ -377,19 +377,4 @@ Resource Leak
377
 
378
  ## Task
379
 
380
- Analyze the bug information provided above. Your task is to:
381
-
382
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
383
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
384
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
385
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
386
-
387
- ### Analysis Questions:
388
- - What was the specific bug or issue in the original code?
389
- - What scenarios would trigger this bug?
390
- - How does the fix address the root cause?
391
- - Are there any potential edge cases the fix might miss?
392
- - What coding practices could have prevented this bug?
393
- - Are there alternative ways to implement the fix?
394
-
395
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
377
 
378
  ## Task
379
 
380
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-3820/instruction.md CHANGED
@@ -899,19 +899,4 @@ Thread Safety Violation
899
 
900
  ## Task
901
 
902
- Analyze the bug information provided above. Your task is to:
903
-
904
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
905
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
906
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
907
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
908
-
909
- ### Analysis Questions:
910
- - What was the specific bug or issue in the original code?
911
- - What scenarios would trigger this bug?
912
- - How does the fix address the root cause?
913
- - Are there any potential edge cases the fix might miss?
914
- - What coding practices could have prevented this bug?
915
- - Are there alternative ways to implement the fix?
916
-
917
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
899
 
900
  ## Task
901
 
902
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-3829/instruction.md CHANGED
@@ -843,19 +843,4 @@ Thread Safety Violation
843
 
844
  ## Task
845
 
846
- Analyze the bug information provided above. Your task is to:
847
-
848
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
849
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
850
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
851
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
852
-
853
- ### Analysis Questions:
854
- - What was the specific bug or issue in the original code?
855
- - What scenarios would trigger this bug?
856
- - How does the fix address the root cause?
857
- - Are there any potential edge cases the fix might miss?
858
- - What coding practices could have prevented this bug?
859
- - Are there alternative ways to implement the fix?
860
-
861
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
843
 
844
  ## Task
845
 
846
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-4002/instruction.md CHANGED
@@ -509,19 +509,4 @@ Null Dereference
509
 
510
  ## Task
511
 
512
- Analyze the bug information provided above. Your task is to:
513
-
514
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
515
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
516
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
517
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
518
-
519
- ### Analysis Questions:
520
- - What was the specific bug or issue in the original code?
521
- - What scenarios would trigger this bug?
522
- - How does the fix address the root cause?
523
- - Are there any potential edge cases the fix might miss?
524
- - What coding practices could have prevented this bug?
525
- - Are there alternative ways to implement the fix?
526
-
527
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
509
 
510
  ## Task
511
 
512
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-4230/instruction.md CHANGED
@@ -569,19 +569,4 @@ Resource Leak
569
 
570
  ## Task
571
 
572
- Analyze the bug information provided above. Your task is to:
573
-
574
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
575
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
576
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
577
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
578
-
579
- ### Analysis Questions:
580
- - What was the specific bug or issue in the original code?
581
- - What scenarios would trigger this bug?
582
- - How does the fix address the root cause?
583
- - Are there any potential edge cases the fix might miss?
584
- - What coding practices could have prevented this bug?
585
- - Are there alternative ways to implement the fix?
586
-
587
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
569
 
570
  ## Task
571
 
572
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-4239/instruction.md CHANGED
@@ -212,19 +212,4 @@ Thread Safety Violation
212
 
213
  ## Task
214
 
215
- Analyze the bug information provided above. Your task is to:
216
-
217
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
218
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
219
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
220
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
221
-
222
- ### Analysis Questions:
223
- - What was the specific bug or issue in the original code?
224
- - What scenarios would trigger this bug?
225
- - How does the fix address the root cause?
226
- - Are there any potential edge cases the fix might miss?
227
- - What coding practices could have prevented this bug?
228
- - Are there alternative ways to implement the fix?
229
-
230
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
212
 
213
  ## Task
214
 
215
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-4466/instruction.md CHANGED
@@ -112,19 +112,4 @@ Null Dereference
112
 
113
  ## Task
114
 
115
- Analyze the bug information provided above. Your task is to:
116
-
117
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
118
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
119
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
120
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
121
-
122
- ### Analysis Questions:
123
- - What was the specific bug or issue in the original code?
124
- - What scenarios would trigger this bug?
125
- - How does the fix address the root cause?
126
- - Are there any potential edge cases the fix might miss?
127
- - What coding practices could have prevented this bug?
128
- - Are there alternative ways to implement the fix?
129
-
130
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
112
 
113
  ## Task
114
 
115
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-4493/instruction.md CHANGED
@@ -392,19 +392,4 @@ Thread Safety Violation
392
 
393
  ## Task
394
 
395
- Analyze the bug information provided above. Your task is to:
396
-
397
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
398
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
399
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
400
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
401
-
402
- ### Analysis Questions:
403
- - What was the specific bug or issue in the original code?
404
- - What scenarios would trigger this bug?
405
- - How does the fix address the root cause?
406
- - Are there any potential edge cases the fix might miss?
407
- - What coding practices could have prevented this bug?
408
- - Are there alternative ways to implement the fix?
409
-
410
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
392
 
393
  ## Task
394
 
395
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-4654/instruction.md CHANGED
@@ -127,19 +127,4 @@ Null Dereference
127
 
128
  ## Task
129
 
130
- Analyze the bug information provided above. Your task is to:
131
-
132
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
133
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
134
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
135
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
136
-
137
- ### Analysis Questions:
138
- - What was the specific bug or issue in the original code?
139
- - What scenarios would trigger this bug?
140
- - How does the fix address the root cause?
141
- - Are there any potential edge cases the fix might miss?
142
- - What coding practices could have prevented this bug?
143
- - Are there alternative ways to implement the fix?
144
-
145
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
127
 
128
  ## Task
129
 
130
+ Fix the bug in the code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inferredbugs-4699/instruction.md CHANGED
@@ -330,19 +330,4 @@ Null Dereference
330
 
331
  ## Task
332
 
333
- Analyze the bug information provided above. Your task is to:
334
-
335
- 1. **Understand the Bug**: Examine the buggy code and identify what the issue was
336
- 2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
337
- 3. **Evaluate the Fix**: Understand how the after code addresses the issue
338
- 4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
339
-
340
- ### Analysis Questions:
341
- - What was the specific bug or issue in the original code?
342
- - What scenarios would trigger this bug?
343
- - How does the fix address the root cause?
344
- - Are there any potential edge cases the fix might miss?
345
- - What coding practices could have prevented this bug?
346
- - Are there alternative ways to implement the fix?
347
-
348
- Use the provided environment to explore, test, or reproduce the bug if needed.
 
330
 
331
  ## Task
332
 
333
+ Fix the bug in the code.