• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

igniterealtime / Smack / #2856

pending completion
#2856

push

github-actions

web-flow
Merge pull request #561 from Flowdalic/github-ci

[github ci] Java 15 → 17

16274 of 41793 relevant lines covered (38.94%)

0.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.46
/smack-core/src/main/java/org/jivesoftware/smack/packet/ErrorIQ.java
1
/**
2
 *
3
 * Copyright © 2014-2023 Florian Schmaus
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.jivesoftware.smack.packet;
18

19
import java.util.Objects;
20

21
import javax.xml.namespace.QName;
22

23
/**
24
 * An XMPP error IQ.
25
 * <p>
26
 * According to RFC 6120 § 8.3.1 "4. An error stanza MUST contain an &lt;error/&gt; child element.", so this class can
27
 * only be constructed if a stanza error is provided.
28
 */
29
public final class ErrorIQ extends IQ {
30

31
    public static final String ELEMENT = StanzaError.ERROR;
32

33
    private final IQ request;
34

35
    private ErrorIQ(Builder builder, QName childElementQName) {
36
        super(builder, childElementQName);
1✔
37
        Objects.requireNonNull(builder.getError(), "Must provide an stanza error when building error IQs");
1✔
38
        this.request = builder.request;
1✔
39
    }
1✔
40

41
    public static ErrorIQ createErrorResponse(final IQ request, final StanzaError error) {
42
        Builder builder = new Builder(error, request);
1✔
43
        builder.setError(error);
1✔
44
        return builder.build();
1✔
45
    }
46

47
    @Override
48
    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
49
        if (request == null) {
1✔
50
            return null;
×
51
        }
52

53
        return request.getIQChildElementBuilder(xml);
1✔
54
    }
55

56
    public static Builder builder(StanzaError error) {
57
        return new Builder(error, IqData.EMPTY.ofType(IQ.Type.error));
1✔
58
    }
59

60
    public static Builder builder(StanzaError error, IqData iqData) {
61
        return new Builder(error, iqData);
×
62
    }
63

64
    public static final class Builder extends IqBuilder<Builder, ErrorIQ> {
65

66
        private IQ request;
67

68
        Builder(StanzaError error, IqData iqData) {
69
            super(iqData);
1✔
70
            if (iqData.getType() != IQ.Type.error) {
1✔
71
                throw new IllegalArgumentException("Error IQs must be of type 'error'");
×
72
            }
73
            Objects.requireNonNull(error, "Must provide an stanza error when building error IQs");
1✔
74
            setError(error);
1✔
75
        }
1✔
76

77
        Builder(StanzaError error, IQ request) {
78
            this(error, AbstractIqBuilder.createErrorResponse(request));
1✔
79
            this.request = request;
1✔
80
        }
1✔
81

82
        @Override
83
        public Builder getThis() {
84
            return this;
1✔
85
        }
86

87
        @Override
88
        public ErrorIQ build() {
89
            QName childElementQname = null;
1✔
90
            if (request != null) {
1✔
91
                childElementQname = request.getChildElementQName();
1✔
92
            }
93
            return new ErrorIQ(this, childElementQname);
1✔
94
        }
95

96
    }
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc