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

wmixvideo / nfe / #9462

23 Jul 2026 08:39PM UTC coverage: 50.977% (-0.8%) from 51.794%
#9462

push

web-flow
Refatoração de chaves para suportar CNPJ alfanumérico (NT 2026.004) (#1181)

* Javadoc Warnings invalid input: '<' e '&' literais

* Javadoc Warnings invalid input: '<' e '&' literais

* Refatoração de chaves para suportar CNPJ alfanumérico (NT 2026.004)

* Normaliza char para maiusculo na chave

O cálculo do DV usa valores[i - 1] - '0'. Se a chave vier com letras minúsculas (o que é aceito por alguns validadores de CNPJ na base), o DV calculado muda (ex.: 'a' - '0' != 'A' - '0'), gerando falsos negativos/positivos. Normalize o caractere para maiúsculo antes de converter para o valor numérico.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Diego Fincatto <58352+fincatto@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

12 of 14 new or added lines in 9 files covered. (85.71%)

757 existing lines in 44 files now uncovered.

15132 of 29684 relevant lines covered (50.98%)

0.51 hits per line

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

11.36
/src/main/java/com/fincatto/documentofiscal/validadores/DFXMLValidador.java
1
package com.fincatto.documentofiscal.validadores;
2

3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.net.URISyntaxException;
6
import java.net.URL;
7
import javax.xml.transform.stream.StreamSource;
8
import javax.xml.validation.Schema;
9
import javax.xml.validation.SchemaFactory;
10
import org.xml.sax.SAXException;
11

12
public final class DFXMLValidador {
×
13

14
    private static boolean valida(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
15
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_008i2/%s", xsd));
×
16
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
17
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
18
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
19
        return true;
×
20
    }
21

22
    public static boolean validaLote(final String arquivoXML) throws Exception {
23
        return DFXMLValidador.valida(arquivoXML, "enviNFe_v3.10.xsd");
×
24
    }
25

26
    public static boolean validaNota(final String arquivoXML) throws Exception {
27
        return DFXMLValidador.valida(arquivoXML, "nfe_v3.10.xsd");
×
28
    }
29

30
    public static boolean valida400(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
31
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_010e_NT2025.002_v1.01/%s", xsd));
×
32
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
33
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
34
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
35
        return true;
×
36
    }
37

38
    public static boolean validaLote400(final String arquivoXML) throws Exception {
39
        return DFXMLValidador.valida400(arquivoXML, "enviNFe_v4.00.xsd");
×
40
    }
41

42
    public static boolean validaNota400(final String arquivoXML) throws Exception {
43
        return DFXMLValidador.valida400(arquivoXML, "nfe_v4.00.xsd");
×
44
    }
45

46
    /**
47
     * Valida MDFe. Para evitar "org.xml.sax.SAXParseException", message:
48
     * "Current configuration of the parser doesn't allow a maxOccurs attribute
49
     * value to be set greater than the value 5.000", foi adicionado a linha
50
     * System.setProperty("jdk.xml.maxOccurLimit", "10000");
51
     * <br>
52
     * Schema PL_MDFe_300b_NT012025_1.03: adota CNPJ alfanumerico (NT 2026.004) no tipo TCnpj e
53
     * chave de acesso alfanumerica no tipo TChMDFe/TChCTe/TChNFe. Comparado ao pacote anterior
54
     * (PL_MDFe_300b_NT022024), as demais diferencas sao apenas relaxamentos de schema (campos que
55
     * passam a ser opcionais, novos valores de enumeracao, aumento de maxLength) - nenhum XML
56
     * valido antes deixa de validar apos a troca.
57
     * <br>
58
     * Limitacao conhecida do pacote oficial (arquivo .xsd fornecido pelo governo, nao alterado
59
     * neste projeto): o atributo Id de infMDFe usa um tipo anonimo proprio ainda com o padrao
60
     * numerico "MDFe[0-9]{44}", nao atualizado junto com TChMDFe. Uma chave de acesso realmente
61
     * alfanumerica (letras nas posicoes 6-19) portanto ainda e rejeitada nesse atributo especifico
62
     * ate a SEFAZ/ENCAT corrigir o pacote. Ver MDFProcessadoTest.schemaOficialAindaRejeitaAtributoIdComChaveDeAcessoAlfanumerica.
63
     *
64
     * @param xml
65
     * @param xsd
66
     * @return
67
     * @throws IOException
68
     * @throws SAXException
69
     * @throws URISyntaxException
70
     */
71
    private static boolean validaMDF(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
72
        System.setProperty("jdk.xml.maxOccurLimit", "20000");
1✔
73
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_MDFe_300b_NT012025_1.03/%s", xsd));
1✔
74
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
1✔
75
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
1✔
76
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
1✔
77
        return true;
1✔
78
    }
79

80
    public static boolean validaLoteMDFe(final String arquivoXML) throws Exception {
81
        return DFXMLValidador.validaMDF(arquivoXML, "enviMDFe_v3.00.xsd");
×
82
    }
83

84
    public static boolean validaMDFe(final String arquivoXML) throws Exception {
85
        return DFXMLValidador.validaMDF(arquivoXML, "mdfe_v3.00.xsd");
×
86
    }
87
    
88
    public static boolean validaMDFeProcessado(final String xml) throws Exception {
89
        return DFXMLValidador.validaMDF(xml, "procMDFe_v3.00.xsd");
1✔
90
    }
91

92
    public static boolean validaEventoMDFe(final String xml) throws Exception {
93
        return DFXMLValidador.validaMDF(xml, "eventoMDFe_v3.00.xsd");
×
94
    }
95

96
    public static boolean validaEventoPagamentoOperacaoMDFe(final String xml) throws Exception {
97
        return DFXMLValidador.validaMDF(xml, "evPagtoOperMDFe_v3.00.xsd");
×
98
    }
99

100
    private static boolean validaCTe(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
101
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_CTe_300a_NT2022.001/%s", xsd));
×
102
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
103
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
104
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
105
        return true;
×
106
    }
107

108
    public static boolean validaLoteCTe300(final String arquivoXML) throws Exception {
109
        return DFXMLValidador.validaCTe(arquivoXML, "enviCTe_v3.00.xsd");
×
110
    }
111

112
    public static boolean validaCTeOS300(final String arquivoXML) throws Exception {
113
        return DFXMLValidador.validaCTe(arquivoXML, "cteOS_v3.00.xsd");
×
114
    }
115

116
    public static boolean validaNotaCte(final String arquivoXML) throws Exception {
117
        return DFXMLValidador.validaCTe(arquivoXML, "cte_v3.00.xsd");
×
118
    }
119

120
    public static boolean validaEventoCTe300(final String arquivoXML) throws Exception {
121
        return DFXMLValidador.validaCTe(arquivoXML, "eventoCTe_v3.00.xsd");
×
122
    }
123

124
    public static boolean validaEventoCancelamentoCTe300(final String arquivoXML) throws Exception {
125
        return DFXMLValidador.validaCTe(arquivoXML, "evCancCTe_v3.00.xsd");
×
126
    }
127

128
    public static boolean validaEventoCancelamentoComprovanteEntregaCTe300(final String arquivoXML) throws Exception {
129
        return DFXMLValidador.validaCTe(arquivoXML, "evCancCECTe_v3.00.xsd");
×
130
    }
131

132
    public static boolean validaEventoCartaCorrecaoCTe300(final String arquivoXML) throws Exception {
133
        return DFXMLValidador.validaCTe(arquivoXML, "evCCeCTe_v3.00.xsd");
×
134
    }
135

136
    public static boolean validaEventoComprovanteEntregaCTe300(final String arquivoXML) throws Exception {
137
        return DFXMLValidador.validaCTe(arquivoXML, "evCECTe_v3.00.xsd");
×
138
    }
139

140
    public static boolean validaEventoEpecCTe300(final String arquivoXML) throws Exception {
141
        return DFXMLValidador.validaCTe(arquivoXML, "evEPECCTe_v3.00.xsd");
×
142
    }
143

144
    public static boolean validaEventoGtvCTe300(final String arquivoXML) throws Exception {
145
        return DFXMLValidador.validaCTe(arquivoXML, "evGTV_v3.00.xsd");
×
146
    }
147

148
    public static boolean validaEventoPrestacaoEmDesacordoCTe300(final String arquivoXML) throws Exception {
149
        return DFXMLValidador.validaCTe(arquivoXML, "evPrestDesacordo_v3.00.xsd");
×
150
    }
151

152
    public static boolean validaEventoRegistroMultimodalCTe300(final String arquivoXML) throws Exception {
153
        return DFXMLValidador.validaCTe(arquivoXML, "evRegMultimodal_v3.00.xsd");
×
154
    }
155

156
    private static boolean validaCTe400(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
157
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_CTe_400_NT2025.001_RTC_1.14/%s", xsd));
1✔
158
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
1✔
159
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
1✔
160
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
161
        return true;
×
162
    }
163

164
    public static boolean validaNotaCte400(final String arquivoXML) throws Exception {
165
        return DFXMLValidador.validaCTe400(arquivoXML, "cte_v4.00.xsd");
×
166
    }
167

168
    public static boolean validaNotaCTeOS400(final String arquivoXML) throws Exception {
169
        return DFXMLValidador.validaCTe400(arquivoXML, "cteOS_v4.00.xsd");
×
170
    }
171

172
    public static boolean validaNotaCteSimp400(final String arquivoXML) throws Exception {
173
        return DFXMLValidador.validaCTe400(arquivoXML, "cteSimp_v4.00.xsd");
×
174
    }
175

176
    public static boolean validaEventoCTe400(final String arquivoXML) throws Exception {
177
        return DFXMLValidador.validaCTe400(arquivoXML, "eventoCTe_v4.00.xsd");
×
178
    }
179

180
    public static boolean validaEventoCancelamentoCTe400(final String arquivoXML) throws Exception {
181
        return DFXMLValidador.validaCTe400(arquivoXML, "evCancCTe_v4.00.xsd");
×
182
    }
183

184
    public static boolean validaEventoCancelamentoComprovanteEntregaCTe400(final String arquivoXML) throws Exception {
185
        return DFXMLValidador.validaCTe400(arquivoXML, "evCancCECTe_v4.00.xsd");
×
186
    }
187

188
    public static boolean validaEventoCartaCorrecaoCTe400(final String arquivoXML) throws Exception {
189
        return DFXMLValidador.validaCTe400(arquivoXML, "evCCeCTe_v4.00.xsd");
×
190
    }
191

192
    public static boolean validaEventoComprovanteEntregaCTe400(final String arquivoXML) throws Exception {
193
        return DFXMLValidador.validaCTe400(arquivoXML, "evCECTe_v4.00.xsd");
×
194
    }
195

196
    public static boolean validaEventoEpecCTe400(final String arquivoXML) throws Exception {
197
        return DFXMLValidador.validaCTe400(arquivoXML, "evEPECCTe_v4.00.xsd");
×
198
    }
199

200
    public static boolean validaEventoGtvCTe400(final String arquivoXML) throws Exception {
201
        return DFXMLValidador.validaCTe400(arquivoXML, "evGTV_v4.00.xsd");
×
202
    }
203

204
    public static boolean validaEventoPrestacaoEmDesacordoCTe400(final String arquivoXML) throws Exception {
205
        return DFXMLValidador.validaCTe400(arquivoXML, "evPrestDesacordo_v4.00.xsd");
×
206
    }
207

208
    public static boolean validaEventoRegistroMultimodalCTe400(final String arquivoXML) throws Exception {
209
        return DFXMLValidador.validaCTe400(arquivoXML, "evRegMultimodal_v4.00.xsd");
×
210
    }
211

212
    public static boolean validaEventoCancelamentoPrestacaoEmDesacordoCTe400(final String arquivoXML) throws Exception {
213
        return DFXMLValidador.validaCTe400(arquivoXML, "evCancPrestDesacordo_v4.00.xsd");
×
214
    }
215

216
    public static boolean validaEventoCancelamentoInsucessoEntregaCTe400(final String arquivoXML) throws Exception {
217
        return DFXMLValidador.validaCTe400(arquivoXML, "evCancIECTe_v4.00.xsd");
×
218
    }
219

220
    public static boolean validaEventoInsucessoEntregaCTe400(final String arquivoXML) throws Exception {
221
        return DFXMLValidador.validaCTe400(arquivoXML, "evIECTe_v4.00.xsd");
×
222
    }
223

224
    private static boolean validaDfe(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
225
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_NFeDistDFe_102/%s", xsd));
×
UNCOV
226
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
UNCOV
227
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
228
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
229
        return true;
×
230
    }
231
    private static boolean validaDistribuicaoCTe(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
232
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_CTeDistDFe_100/%s", xsd));
×
UNCOV
233
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
UNCOV
234
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
235
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
UNCOV
236
        return true;
×
237
    }
238
    public static boolean validaDistribuicaoCTe(final String arquivoXML) throws IOException, SAXException, URISyntaxException {
239
        return DFXMLValidador.validaDistribuicaoCTe(arquivoXML, "distDFeInt_v1.00.xsd");
×
240
    }
241

242
    private static boolean validaDistribuicaoMDFe(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
243
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_MDFeDistDFe_100/%s", xsd));
×
UNCOV
244
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
UNCOV
245
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
246
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
UNCOV
247
        return true;
×
248
    }
249
    public static boolean validaDistribuicaoMDFe(final String arquivoXML) throws IOException, SAXException, URISyntaxException {
250
        return DFXMLValidador.validaDistribuicaoMDFe(arquivoXML, "distDFeInt_v1.00.xsd");
×
251
    }
252
    
253
    public static boolean validaConsultaDfe(final String arquivoXML) throws Exception {
254
        return DFXMLValidador.validaDfe(arquivoXML, "distDFeInt_v1.01.xsd");
×
255
    }
256

257
    private static boolean validaEpec(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
258
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/Evento_EPEC_PL_v1.01/%s", xsd));
×
UNCOV
259
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
UNCOV
260
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
UNCOV
261
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
262
        return true;
×
263
    }
264

265
    public static boolean validaEpec(final String arquivoXML) throws Exception {
266
        return DFXMLValidador.validaEpec(arquivoXML, "envEPEC_v1.00.xsd");
×
267
    }
268

269
    public static boolean validaEventoEpec(final String arquivoXML) throws Exception {
UNCOV
270
        return DFXMLValidador.validaEpec(arquivoXML, "EPEC_v1.00.xsd");
×
271
    }
272
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc