<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/77740>77740</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format: SpacesInSquareBrackets does not work properly for Java
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mikir
</td>
</tr>
</table>
<pre>
The following Java snippet
```
public class Sample
{
public static void createObject(Object[] arguments)
{
final int numElements = arguments.length;
final Class<?>[] types = new Class<?>[numElements];
for (int i = 0; i < numElements; ++i)
types[i] = arguments[i].getClass();
}
}
```
using the following clang-format configuration
```
---
Language: Java
BasedOnStyle: Microsoft
SpacesInSquareBrackets: false
...
```
is formatted as
```
public class Sample
{
public static void createObject(Object[] arguments)
{
final int numElements = arguments.length;
final Class<?>[] types = new Class<?>[ numElements ]; // wrong, spaces even if SpacesInSquareBrackets is false
for (int i = 0; i < numElements; ++i)
types[i] = arguments[i].getClass(); // ok, no spaces
}
}
```
We are using clang-format Ubuntu clang-format version 14.0.0-1ubuntu1.1.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVE2PgzYQ_TXmMgoyBgIcOIRkI7VqtYe06tnAQNwYm9omUf59ZWCbRLtdVe21KCLOZD7ezHtjbq3oFWJJ0oqkh4BP7qxNOYiLMEGt23v5yxmh01Lqm1A9_MivHKwS44iO0AOhu_W9petn_jlOtRQNNJJbCyc-jBJXv6xaDgAAq5d13IkGrlq00BjkDt_r37FxhOXrYcYG3PTTgMpZwopHkpeM_umE4hKEcqCm4U3iHAIkfkoQSlS9O5P4y9C9R03iPYmPJH5bi7v7iEsWhbfPLk-lSHr4nFgbICz3oMSchJK4mo_7Z5TeSFhFWCUePc6VSVoJD-OljdUY9ugWQCz3YX8VJ9nhY-qHL2la3pP1zLoXnhvJVb_ptBm4g0arTvST4U5o9Q3rm81mOfzEVT_xHkm8mxWzWCtusX1XJ3eX8z8_i8Zoq7tVSKeRN2h_UKc_Jm6wMry5oB_JDjou7aqfMAy_6URYWCA7bIHb_wX6cHmtNUsUCDsSdoSb0aonbA92ZgDwigpEB18TAn7ID0L-k7Sfnn-h8g_8-uLBK73if578P9L_bwjcICxr8CL8X-tJuenVdkVjhVYQJSEN6SaaZp8ojMKgLeO2iAseYBllNCm2LI-T4FzGTVYUeV3XeVpT5CnSuC22HS9YFNUsoYEoGWUJjaKI5kkWJeE2j2iSZ2nKuxizNCIJxYELGUp5HUJt-kBYO2GZZVlCA8lrlHa-whl7BksY85e6KX3Ypp56SxIqhfUC-0jkhJNYvkTFu7_jvtVoQWkHN20uMBo9opH3WQN-z4PJyPLs3OjXdmGnF-481WGjB8KOvuj6tRmNXnboOLdiCTvO3fwZAAD__6l78h8">